HDU 1029 Ignatius and the Princess IV

http://acm.hdu.edu.cn/showproblem.php?pid=1029

看题意就是建立一个映射,用map直接过

View Code
#include <iostream>
#include <map>
using namespace std;
int main()
{
    int n;
    while(~scanf("%d",&n))
    {
        map <int ,int > M;
        int bz=(n+1)/2;
        while(n--)
        {
            int a;
            scanf("%d",&a);
            M[a]++;
        }
        map <int ,int > :: iterator it;
        for(it=M.begin();it!=M.end();it++)
            if(it->second >= bz)
            {
                cout << it->first << endl ;
                break;
            }
    }
    return 0;
} 
原文地址:https://www.cnblogs.com/xiaohongmao/p/2509083.html