【CUGBACM15级BC第20场 A】hdu 5123 who is the best?

来源:互联网 发布:手机淘宝撤销投诉 编辑:程序博客网 时间:2024/05/22 16:56

who is the best?

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


Problem Description
There are N people want to choose the best person. Each person select the best personai, .John wants to know that who received the most number of votes.
 

Input
The first line contains a single integerT(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
21012345678910533333
 

Sample Output
13
 
水题没啥好说的
#include <iostream>#include <set>#include <map>#include <stack>#include <cmath>#include <queue>#include <cstdio>#include <bitset>#include <string>#include <vector>#include <iomanip>#include <cstring>#include <algorithm>#include <functional>#define PI acos(-1)#define eps 1e-8#define inf 0x3f3f3f3f#define debug(x) cout<<"---"<<x<<"---"<<endltypedef long long ll;using namespace std;struct ff{    int num;    int vote;} a[150];bool cmp(ff a, ff b){    if (a.vote == b.vote)    {        return a.num < b.num;    }    return a.vote > b.vote;}int main(){    int t;    cin >> t;    while (t--)    {        memset(a, 0, sizeof(a));        int n;        cin >> n;        int xx;        for (int i = 1; i <= n; i++)        {            cin >> xx;            a[i].num = i;            a[xx].vote++;        }        sort(a + 1, a + 1 + n, cmp);        cout << a[1].num << endl;    }    return 0;}


原创粉丝点击