使用了hasmap求解哦
#include <iostream>
#include <vector>
#include <algorithm>
#include <unordered_map>
using namespace std;
void findMode() {
unordered_map<int, int> ump;
int num;
while (getchar() != ']')
{
cin >> num;
ump[num]++;
}
int maxi = ump[0]; //最多出现次数
int idx = 0; //最多出现次数对应在unordered_map中的键
int len = ump.size();
for (auto t: ump) {
if (maxi < t.second) {
maxi = t.second;
idx = t.first;
}
}
cout << idx << endl;
}
int main() {
findMode();
return 0;
} 


京公网安备 11010502036488号