GYM 101653 N.Majority(水~)

Description

给出 n 个整数,问其中出现数量最多且数值最小的数字

Input

第一行一整数 T 表示用例组数,每组用例首先输入一整数 n ,之后输入 n 个整数 a 1 , . . . , a n

( 1 n 100 , 1 a i 1000 )

Output

输出出现数量最多且数值最小的数字

Sample Input

3
3
42
42
19
4
7
99
99
7
5
11
12
13
14
15

Sample Output

42
7
11

Solution

简单题,统计每个数字出现的次数选个最大值即可

Code

#include<cstdio>
#include<iostream>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<vector>
#include<queue>
#include<map>
#include<set>
#include<ctime>
using namespace std;
typedef long long ll;
typedef pair<int,int>P;
const int INF=0x3f3f3f3f,maxn=1005;
int T,n,num[maxn];
int main()
{
    scanf("%d",&T);
    while(T--)
    {
        scanf("%d",&n);
        memset(num,0,sizeof(num));
        while(n--)
        {
            int a;
            scanf("%d",&a);
            num[a]++;
        }
        int ans=1;
        for(int i=2;i<=1000;i++)
            if(num[i]>num[ans])ans=i;
        printf("%d\n",ans);
    }
    return 0;
}

猜你喜欢

转载自blog.csdn.net/v5zsq/article/details/80404924