#include <stdio.h>
#include <stdlib.h>
#define COUNT 5
int check_number(char* str) {
size_t i = 0;
if (!str || str[0] == '\0') return 0;
if (str[0] == '-' || str[0] == '+') i = 1;
for(;str[i] != '\0'; ++i) {
if (str[i] < '0' || str[i] > '9') return 0;
}
return 1;
}
int count_symbol(char* str, char symbol) {
int count = 0;
for (; *str != '\0'; ++str)
if (*str == symbol) ++count;
return count;
}
int main(void) {
char numbers[COUNT][12]; // 12 = sign + 10 digits + \0
size_t i;
int tmp;
int max3 = 0;
int max3Index = 0;
printf("Vvedite %d chisel:\n", COUNT
); for (i = 0; i < COUNT; ++i) {
if (!check_number(numbers[i])) {
--i;
continue;
}
printf("Chislo[%d] = %s\n", i
+ 1, numbers
[i
]); if ((tmp = count_symbol(numbers[i], '3')) > max3) {
max3Index = i;
max3 = tmp;
}
}
printf("\nChislo s dlinneishim 3 - chislo[%d] = %s\n", max3Index
+ 1, numbers
[max3Index
]); return 0;
}
I2luY2x1ZGUgPHN0ZGlvLmg+CiNpbmNsdWRlIDxzdGRsaWIuaD4KCiNkZWZpbmUgQ09VTlQgNQoKaW50IGNoZWNrX251bWJlcihjaGFyKiBzdHIpIHsKCXNpemVfdCBpID0gMDsKCWlmICghc3RyIHx8IHN0clswXSA9PSAnXDAnKSByZXR1cm4gMDsKCWlmIChzdHJbMF0gPT0gJy0nIHx8IHN0clswXSA9PSAnKycpIGkgPSAxOwoJZm9yKDtzdHJbaV0gIT0gJ1wwJzsgKytpKSB7CgkJaWYgKHN0cltpXSA8ICcwJyB8fCBzdHJbaV0gPiAnOScpIHJldHVybiAwOwoJfQoJcmV0dXJuIDE7Cn0KCmludCBjb3VudF9zeW1ib2woY2hhciogc3RyLCBjaGFyIHN5bWJvbCkgewoJaW50IGNvdW50ID0gMDsKCWZvciAoOyAqc3RyICE9ICdcMCc7ICsrc3RyKQoJCWlmICgqc3RyID09IHN5bWJvbCkgKytjb3VudDsKCXJldHVybiBjb3VudDsKfQoKaW50IG1haW4odm9pZCkgewoJ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