/* Time: April 7, 2018 09:57:47 Idea: Divide the digits of the numbers and put them in b[10]={0}. If the separated number is 4, directly make b[4]++, at this time the number of elements in b[4] becomes 1, separate 4 again, continue b[4]++, and calculate each b[i] in turn , and then compare to get the largest b[i]. Note that when printing, the two largest b[i] may be equal, At this point it needs to be printed out. */ #include<stdio.h> #define N 1000 #define NUM 10 intmain() { int i, n; int a[N]; int b[NUM] = {0}; //Smart use of ten-element array, subscripts and numbers just correspond int t = -1; int max = -1; scanf("%d", &n); for (i = 0; i < n; i++) { scanf("%d", &a[i]); } for (i = 0; i < n; i++) { while (a[i] != 0) //The default four-digit number here is not in the form of 0458. { t = a[i] % 10; b[t]++; a[i] = a[i] / 10; } } for (i = 0; i < NUM; i++) { if (b[i] > max) { max = b[i]; } } printf("%d:", max); for (i = 0; i < NUM; i++) { if (max == b[i]) { printf("%d", i); //print i } } return 0; }
Experiment 7-1-6 Find the most one-digit number in a batch of integers (20 points)
Guess you like
Origin http://10.200.1.11:23101/article/api/json?id=326703562&siteId=291194637
Recommended
Ranking