Skip to content

Instantly share code, notes, and snippets.

@madsunrise
Created May 22, 2019 17:28
Show Gist options
  • Select an option

  • Save madsunrise/6024d9fc706a7b0bcacd184066db1307 to your computer and use it in GitHub Desktop.

Select an option

Save madsunrise/6024d9fc706a7b0bcacd184066db1307 to your computer and use it in GitHub Desktop.
#include <iostream>
#include <unordered_map>
using namespace std;
int main() {
int n;
cin >> n;
unordered_map<int, int> map;
for (int i = 0; i < n; ++i) {
int k;
cin >> k;
unordered_map<int, int>::const_iterator iter = map.find(k);
if (iter == map.end()) {
map[k] = 0;
} else {
map[k] = map[k] + 1;
}
}
int maxKey = 0, maxValue = 0;
for (auto it : map) {
if (it.second > maxValue || (it.second == maxValue && it.first > maxKey)) {
maxValue = it.second;
maxKey = it.first;
}
}
cout << maxKey;
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment