Run ID:111971
提交时间:2025-03-08 11:37:18
#include <iostream> #include <unordered_map> #include <vector> #include <algorithm> using namespace std; int main() { int n; cin >> n; unordered_map<int, int> countMap; for (int i = 0; i < n; ++i) { int num; cin >> num; countMap[num]++; } int mostFrequent = -1; int maxCount = 0; for (auto& pair : countMap) { if (pair.second > maxCount || (pair.second == maxCount && pair.first < mostFrequent)) { mostFrequent = pair.first; maxCount = pair.second; } } cout << mostFrequent << endl; return 0; }