现在的位置: 首页 > 综合 > 正文

HDU 5123 who is the best? hash统计

2018年01月19日 ⁄ 综合 ⁄ 共 925字 ⁄ 字号 评论关闭

who is the best?

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 316    Accepted Submission(s): 211

Problem Description
There are N people want to choose the best person. Each person select the best person
ai,
.John wants to know that who received the most number of votes.
Input
The first line contains a single integer
T(1T50),indicating
the number of test cases.
Each test case begins with an integer N(1N100),indicating
the number of person.
Next N lines contains an integer ai(1aiN).
Output
For each case, output an integer means who is the best person. If there are multiple answers, print the minimum index.
Sample Input
2 10 1 2 3 4 5 6 7 8 9 10 5 3 3 3 3 3
Sample Output
1 3
#include<iostream>
#include<stdio.h>
using namespace std;
#define N 105
int sum[N];

int main()
{
	int n,m,i,k,max;
	scanf("%d",&n);
	while(n--)
	{
		scanf("%d",&m);
		memset(sum,0,sizeof(sum));
		max=-1;
		for(i=0;i<m;i++)
		{
			scanf("%d",&k);
			sum[k]++;
			if(sum[k]>max)
				max=sum[k];
		}
		for(i=0;i<N;i++)
		{
			if(max==sum[i])
				break;
		}
		printf("%d\n",i);
	} 	
	return 0;
}

抱歉!评论已关闭.