本题要求统计一个整型序列中出现次数最多的整数及其出现次数。
输入格式:
输入在一行中给出序列中整数个数N(0<N≤1000),以及N个整数。数字间以空格分隔。
输出格式:
在一行中输出出现次数最多的整数及其出现次数,数字间以空格分隔。题目保证这样的数字是唯一的。
输入样例:
10 3 2 -1 5 3 4 3 0 3 2
结尾无空行
输出样例:
3 4#include<stdio.h>
int main(){
int n,i,j;
scanf("%d",&n);
int a[10000];//不要定义成二维数组
int count=0;
int max=0,maxcount=0;
for(i=0;i<n;i++){
scanf("%d",&a[i]);
}
for(i=0;i<n;i++){
for(j=0;j<n;j++){
if(a[i]==a[j]){
count++;
}
}
if(count>maxcount)
{
maxcount=count;
max=a[i];
}
count=0;
}
printf("%d %d",max,maxcount);
return 0;
}