专业的响应式网站建设,建材营销型的网站,佛山做网站哪家公司好,打广告专用配图题目#xff1a;
给n个整数#xff0c;求里面出现次数最多的数#xff0c;如果有多个重复出现的数#xff0c;求出值最大的一个。 样例输入#xff1a; 10 9 10 27 4 9 10 3 1 2 6 样例输出#xff1a; 10 2
分析与解答#xff1a;
遍历map是根据自动键的大小从小到大…题目
给n个整数求里面出现次数最多的数如果有多个重复出现的数求出值最大的一个。 样例输入 10 9 10 27 4 9 10 3 1 2 6 样例输出 10 2
分析与解答
遍历map是根据自动键的大小从小到大遍历的。这里如果出现次数相等也要更新。
#includeiostream
#includecstdio
#includemap
#includealgorithmusing namespace std;
mapint,int mp;
int main(){int n,x,a,b;cinn;for(int i0;in;i){cinx;mp[x];}b0;for(mapint,int::iterator it mp.begin();it!mp.end();it){if(it-second b) {bit-second;ait-first;}}couta b;return 0;
}