fork download
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3.  
  4. #define COUNT 5
  5.  
  6. int check_number(char* str) {
  7. size_t i = 0;
  8. if (!str || str[0] == '\0') return 0;
  9. if (str[0] == '-' || str[0] == '+') i = 1;
  10. for(;str[i] != '\0'; ++i) {
  11. if (str[i] < '0' || str[i] > '9') return 0;
  12. }
  13. return 1;
  14. }
  15.  
  16. int count_symbol(char* str, char symbol) {
  17. int count = 0;
  18. for (; *str != '\0'; ++str)
  19. if (*str == symbol) ++count;
  20. return count;
  21. }
  22.  
  23. int main(void) {
  24. char numbers[COUNT][12]; // 12 = sign + 10 digits + \0
  25. size_t i;
  26.  
  27. int tmp;
  28. int max3 = 0;
  29. int max3Index = 0;
  30.  
  31. printf("Vvedite %d chisel:\n", COUNT);
  32. for (i = 0; i < COUNT; ++i) {
  33. scanf("%s", numbers[i]);
  34. if (!check_number(numbers[i])) {
  35. printf("Escho raz\n");
  36. --i;
  37. continue;
  38. }
  39. printf("Chislo[%d] = %s\n", i + 1, numbers[i]);
  40. if ((tmp = count_symbol(numbers[i], '3')) > max3) {
  41. max3Index = i;
  42. max3 = tmp;
  43. }
  44. }
  45. printf("\nChislo s dlinneishim 3 - chislo[%d] = %s\n", max3Index + 1, numbers[max3Index]);
  46. return 0;
  47. }
Success #stdin #stdout 0s 2160KB
stdin
12345 767
23we
7ti8

33333
33
33333
stdout
Vvedite 5 chisel:
Chislo[1] = 12345
Chislo[2] = 767
Escho raz
Escho raz
Chislo[3] = 33333
Chislo[4] = 33
Chislo[5] = 33333

Chislo s dlinneishim 3 - chislo[3] = 33333