1 #include<stdio.h> 2 3 int main(void) 4 { 5 int n; 6 int number[1000]; 7 int digit[10] = {0}; //记录每个数字出现的次数 8 int temp; 9 10 scanf_s("%d", &n); 11 for (int i = 0; i < n; i++) 12 { 13 scanf_s("%d", &number[i]); 14 } 15 16 for (int i = 0; i < n; i++) 17 { 18 do 19 { 20 temp = number[i] % 10; 21 digit[temp]++; 22 number[i] = number[i] / 10; 23 } while (number[i] > 0); 24 } 25 26 int max_index = 0; 27 for (int i = 1; i < 10; i++) 28 { 29 if (digit[i] > digit[max_index]) 30 { 31 max_index = i; 32 } 33 } 34 35 printf("%d:", digit[max_index]); 36 for (int i = 0; i < 10; i++) 37 { 38 if (digit[i] == digit[max_index]) 39 { 40 printf(" %d", i); 41 } 42 } 43 44 printf("\n"); 45 46 return 0; 47 }
原文地址:https://www.cnblogs.com/2018jason/p/11993939.html
时间: 2024-11-12 18:37:28