Home > Back-end >  Bosses can help kangkang my wrong code
Bosses can help kangkang my wrong code

Time:11-28

5-6 for a group of integers in the unit digit of the most (17 points)

Given a group of integers, each integer of each digit, appear most times unit digit; for example given three integer 1234234 5345 6, the Numbers are 3 and 4 in most times, are the three times,

Input format:

Input in line 1 is given positive integer N (1000) or less, in the second line type N is less than the whole range of nonnegative integers, separated by Spaces between Numbers,

The output format:

According to the format in one line "M: n1 n2... "The number of output, which M is biggest, n1, and n2,... For the unit digit of appear most times, the order by size, Numbers separated by Spaces, but can not have surplus space, at the end of the

Input the sample:

3, 1234, 2345, 3456

The output sample:
3:3, 4,

#include
Int main (void)
{
Int n, I, x, Max=0;
Int a, [10].
The scanf (" % d ", & amp; N);
for(i=0; i<10; I++)
A [I]=0;
for(i=0; iThe scanf (" % d ", & amp; x);
While (x> 0 {
A, [10] x % + +.
X/=10;
}
}
for(i=0; i<10; I++) {
If (a [I] & gt; Max)
Max=a, [I].
}
Printf (" % d:, "Max);
for(i=0; i<10; I++) {
If (Max==a [I])
Printf (" % d ", I);
}
return 0;
}

CodePudding user response:

0 n input, the result will be output
0:0 1 2 3 4 5 6 7 8 9
The results conform to the do not conform to the requirements of the subject, if does not conform to, to get rid of the results (the program add a judgment of n is greater than 0 to continue to do processing)

CodePudding user response:

And input 3 0 0 0, the output should be 3:0
But the result of the code is 0:0 1 2 3 4 5 6 7 8 9
Because did not enter the while (x> 0), so a [0] are not additive

CodePudding user response:

Modified as follows, for your reference:
 # include 
Int main (int arg c, char * argv [])
{
Int n, I, x, Max=0;
Int a [10]={0};

The scanf (" % d ", & amp; N);
If (n==0) return 1;//if n=0 exit

for(i=0; i{
The scanf (" % d ", & amp; x);
If (x==0)//here to join the '0' count
{
A [0] + +;
}
The else
{
While (x!=0)//judgment condition here to 'x!
=0 '{
A, [10] x % + +.
X/=10;
}
}
}
for(i=0; i<10; I++)
If (a [I] & gt; Max)
Max=a, [I].
Printf (" % d:, "Max);

for(i=0; i<10; I++)
If (Max==a [I])
Printf (" % d ", I);

printf("\n");
return 0;
}
  • Related