输入10个数,找出出现次数最多的数 (如果多个并列,则按数字出现顺序分别输出)
#include <stdio.h>
int main(int argc, const char * argv[])
{
int a[10],count[10]={0};
int i,j,temp;
for (i = 0; i < 10; i++) {
scanf("%d",&a[i]);
}
for (i = 0; i < 9; i++) {
count[i] = 1;
for (j = i + 1; j < 10; j++) {
if (a[i] == a[j]) {
count[i]++;
}
}
}
for (i = 0; i < 9; i++) {
for (j = i + 1; j < 10; j++) {
if (count[i] < count[j]) {
temp = count[i];
count[i] = count[j];
count[j] =temp;
temp = a[i];
a[i] = a[j];
a[j] =temp;
}
}
}
for (i = 0; i < 10; i++) {
if (count[i] == count[i+1]) {
printf("%d ",a[i]);
}
else{
printf("%d ",a[i]);
break;
}
}
return 0;
}