给定一批整数,分析每个整数的每一位数字,求出现次数最多的个位数字。例如给定3个整数1234、2345、3456,其中出现最多次数的数字是3和4,均出现了3次。
输入格式:
输入在第1行中给出正整数N(<=1000),在第2行中给出N个不超过整型范围的正整数,数字间以空格分隔。
输出格式:
在一行中按格式“M: n1 n2 ...”输出,其中M是最大次数,n1、n2、……为出现次数最多的个位数字,按从小到大的顺序排列。数字间以空格分隔,但末尾不得有多余空格。
输入样例:3 1234 2345 3456输出样例:
3: 3 4#include<stdio.h> #define N 1000 #define P 10 int main(){ int t, n, a[N], m; int b[P] = { 0 }; scanf("%d", &n); for (t = 0; t < n; ++t){ scanf("%d", &a[t]); } for (t = 0; t < n; ++t){ while (a[t]){ m = a[t] % 10; ++b[m]; a[t] /= 10; } } int times = b[0]; int index = 0; for (t = 1; t < P; ++t){ if (b[t]>times){ times = b[t]; index = t; } } printf("%d:", times); for (t = 0; t < P; ++t){ if (b[t]==times){ printf(" %d", t); } } printf("\n"); return 0; }