一道很典型的题目,本文章仅作备忘使用。
http://acm.sdut.edu.cn/sdutoj/problem.php?action=showproblem&problemid=2521
#include <iostream>
#include <map>
#include <algorithm>
using namespace std;
class comp
{
public:
bool operator () (const pair< int, int > &a, const pair < int, int > &b)
{
return a.second == b.second ? a.first > b.first : a.second < b.second;
}
};
int main()
{
int n;
while(cin>>n)
{
map<int, int> a;
while(n--)
{
int num;
cin>>num;
++a[num];
}
map<int,int>::iterator it_max = max_element(a.begin(),a.end(),comp());
cout<<it_max->first<<' '<<it_max->second<<endl;
}
}