码迷,mamicode.com
首页 > 其他好文 > 详细

杭电5123 who is the best?

时间:2015-04-12 12:10:06      阅读:120      评论:0      收藏:0      [点我收藏+]

标签:

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(1≤T≤50),indicating the number of test cases.
Each test case begins with an integer N(1≤N≤100),indicating the number of person.
Next N lines contains an integer ai(1≤ai≤N).
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>
#include<string.h>
using namespace std;
int main()
{
    int test,n,k;
    int a[120];
    cin>>test;
    while(test--)
    {
        cin>>n;
        memset(a,0,sizeof(a));
        for(int i=1;i<=n;i++)
        {
            scanf("%d",&k);
            a[k]++;
        }
        int max=0,num;
        for(int i=1;i<=n;i++)
        {
            if(max<a[i])
            {
                max=a[i];
                num=i;
            }
        }
        printf("%d\n",num);
    }
    return 0;
}


杭电5123 who is the best?

标签:

原文地址:http://blog.csdn.net/qq_qingtian/article/details/45008033

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!