#include<iostream>
#include<map>
using namespace std;
int main()
{
map<int, int>m;
int n; cin >> n;
while (n--)
{
int tmp;
cin >> tmp;
if (m[tmp] == 0) m[tmp] = 1;
else m[tmp]++;
}
auto itmax = m.begin();
int max = itmax->second;
for (auto it = m.begin(); it != m.end(); it++)
{
if (it->second > max)
{
itmax = it;
max = itmax->second;
}
}
cout << itmax->first << endl;
return 0;
}
201312-1 出现次数最多的数
本文介绍了一种使用C++ map容器统计并找出一组输入数据中出现频率最高的整数的方法。通过迭代读取输入,更新map中对应数值的计数,最终确定并输出出现次数最多的那个数。

被折叠的 条评论
为什么被折叠?



