C语言 输入一些学生的分数,哪个分数出现的次数最多?如果有多个并列,从小到大输出。

2025-12-17 05:10:37
推荐回答(1个)
回答1:

#include
int main()
{   
    int T,n,a[100010],i,j,counter[101]={0},max=counter[1];
    scanf("%d",&T);
    while(T--)
    {
        scanf("%d",&n);
        for(i=1;i<=n;i++)
{
scanf("%d",&a[i-1]);
}
for(i=0;i {
counter[a[i]]++;
}
max=0;
for(j=1;j<=100;j++)
{
if(max {
max=counter[j];
}
}
for(j=1;j<=100;j++)
{
if(counter[j]==max)
{
printf("%d ",counter[j]);
}
}
printf("\n");
    }
return 0;
}

参考这段代码哈,欢迎交流。