Description
一组数据中出现次数最多的数值,叫众数,有时众数在一组数中有好几个。
Input
有多组测试数据。输入的第一行是整数T(0<T<=10),后接T组测试数据。
每组测试数据为一个整数n(1<n<1000),后接n个整数m(0<m<10000)。
Output
对应每组测试数据,输出出现最多的数的出现次数,同时输出出现最多的数,如果有多个数
出现次数都是最多,按从小到大顺序输出。
Sample Input
1
10 1 2 3 2 1 2 3 1 1 3
Sample Output
4 1
HINT
Append Code
#include<stdio.h>
#include<stdlib.h>
int main()
{
int t, n, data, num, a[10000] = {0};
int i, j, max;
scanf("%d",&t);
for(i = 0; i < t; i++)
{
scanf("%d", &n);
num = 0;
for(j = 0; j < 10000; j++)
a[j] = 0;
for(j = 0; j < n; j++)
{
scanf("%d", &data);
a[data]++;
if(data > num)
num = data;
}
max = 0;
for(j = 0; j <= num; j++)
{
if(a[j] > max)
max = a[j];
}
printf("%d", max);
for(j = 0; j <= num; j++)
{
if(a[j] == max)
printf(" %d", j);
}
printf("\n");
}
return 0;
}