HDU_1029 Ignatius and the Princess IV

  这题的数据有点问题,给的N个数里边最大的数是多少不知道,直接猜了个数用hash做了,居然1A了。。。。

#include <stdio.h>
#include
<string.h>
#define N 100007
int hash[N];
int main()
{
int n, i, a;
while(scanf("%d", &n) != EOF)
{
memset(hash,
0, sizeof(hash));
int max = -1;
while(n--)
{
scanf(
"%d", &a);
if(a > max) max = a;
hash[a]
++;
}
int num = -1, flag;
for(i = 1; i <= max; i++)
if(hash[i] > num)
{
num
= hash[i];
flag
= i;
}
printf(
"%d\n",flag);
}
return 0;
}
原文地址:https://www.cnblogs.com/vongang/p/2129179.html