在c++中有两个关联容器,
第一种是map,内部是按照key排序的,从小到大
第二种是unordered_map,容器内部是无序的,使用hash组织内容的。
#include<iostream>
#include<map>
#include<algorithm>
using namespace std;
int main()
{
map<int,int> mp;
int n;
cin>>n;
int temp;
while(n--)
{
cin>>temp;
mp[temp]++;
}
int ans;
int max=0;
for(auto& it:mp)
{
if(it.second>max)
{
ans=it.first;
max=it.second;
}
}
cout<<ans<<endl;
return 0;
}