求众数 题解:
#include<bits/stdc++.h>
using namespace std;
int main(){
map<int,int> mp;
int n; cin>>n;
for(int i = 0 ; i < n; i++){
int t; cin>>t;
mp[t]++;
}
int ans = 0;
int count = 0;
for(auto it : mp){
if(it.second > count){
count = it.second;
ans = it.first;
}
}
cout<<ans<<endl;
}
登录后发布评论
暂无评论,来抢沙发