hdu_1029_hash/map

时间:2022-05-17 23:37:08

http://acm.hdu.edu.cn/showproblem.php?pid=1029

太水了,一次过,直接上代码吧,只想说最愚蠢的hash都要比map快!

 #include<cstdio>
#include<cstring>
#include<iostream>
#include<cmath>
using namespace std;
const int MAX = *;
const int MOD = ;
int cnt[MAX];
int num[MAX];
void ha(int tm)
{
int tt = tm%MOD;
while(num[tt]!=-) {
if(num[tt]==tm) break;
tt++;
}
num[tt] = tm;
cnt[tt]++;
}
int main()
{
int N;
while(~scanf("%d",&N))
{
memset(num,-,sizeof(num));
memset(cnt,,sizeof(cnt));
int tm;
while(N--){
scanf("%d",&tm);
ha(tm);
}
int m = ;
int u = -;
for(int i = ; i < MAX; i++){
if(cnt[i]>m) {u = i;m = cnt[i];}
}
printf("%d\n",num[u]);
}
return ;
}