Created
May 22, 2019 17:28
-
-
Save madsunrise/6024d9fc706a7b0bcacd184066db1307 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #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