(算法练习)——201312-1出现次数最多的数(CCF模拟)

水题~
AC代码:

#include <stdio.h>
#include <algorithm>
using namespace std;

int hhash[10010];

int main(){
	int n;
	scanf("%d",&n);
	for(int i = 1;i <= 10000;i++){
		hhash[i] = 0;
	}
	int num;
	for(int i = 0;i <n;i++){
		scanf("%d",&num);
		hhash[num]++;
	}
	int max = 0;
	int cnt = 0;
	for(int i = 1;i <= 10000;i++){
		if(hhash[i] >cnt){
			cnt = hhash[i];
			max = i;
		}
		else if(hhash[i] == cnt && i <max){
			max = i;
		}
	}
	printf("%d",max);
}
发布了212 篇原创文章 · 获赞 6 · 访问量 6367

猜你喜欢

转载自blog.csdn.net/weixin_42377217/article/details/104357975
今日推荐