Flying to the Mars

题目地址:http://acm.hdu.edu.cn/showproblem.php?pid=1800
很久没用容器的*max_element了,忘了怎么加排序规则了。记录一下。

#include<bits/stdc++.h>
//#define maxn 100010
using namespace std;
typedef pair<int, int>  P;
map<int,int> a;
bool cmp(const P& p1,const P& p2)
{
    return p1.second<p2.second;
}
int main()
{
    int n;
    while(cin>>n)
    {
        int tmp;
        for(int i=0;i<n;i++)
        {
            scanf("%d",&tmp);
            a[tmp]++;
        }
        int x = (*max_element(a.begin(),a.end(),cmp)).second;
//      int ans = 0;
//      for(map<int,int>::iterator it = a.begin();it!=a.end();it++)
//      {
//          if(it->second>ans)
//              ans = it->second;
//      }
//      cout<<ans<<endl;
        cout<<x<<endl;
        a.clear();
    }
    return 0;
}

猜你喜欢

转载自blog.csdn.net/qq_36734025/article/details/81265278