ZCMU1733 Mode(Map)

Description

  Give you a number of n series, in which a number of more than n / 2 times , you should find out that the number (n<=500000,x<=10^19)

Input

  The first line is a positive integer n. The second line of n positive integers separated by spaces.

Output

A Positive integer on a line indicates that number 

Sample Input

5

3 2 3 1 3

Sample Output

3

思路

输出序列中出现次数超过n/2次的数

代码

#include<iostream>
#include<stdio.h>
#include<map>
using namespace std;
int main()
{
    int n;
    while(cin>>n)
    {
        string str,ans="0";
        map<string,int> s;
        for(int i=0;i<n;i++)
        {
            cin>>str;
            s[str]+=1;
            if(s[str]>n/2) ans=str;
        }
        if(ans!="0")
           cout<<ans<<endl;
    }
    return 0;
}

猜你喜欢

转载自blog.csdn.net/ZCMU_2024/article/details/83082002
Map