fork download
  1. #include <bits/stdc++.h>
  2.  
  3. using namespace std;
  4.  
  5. int main() {
  6. int n;
  7. cin >> n;
  8. vector<int> vec(n);
  9. for (auto &i : vec)
  10. cin >> i;
  11.  
  12. map<int, int> freq;
  13. for (auto i : vec)
  14. freq[i]++;
  15.  
  16. for (auto p : freq)
  17. if (p.second > vec.size() / 2) {
  18. cout << p.first << "\n";
  19. break;
  20. }
  21. return 0;
  22. }
  23.  
Success #stdin #stdout 0s 5308KB
stdin
10
2 2 2 2 2 2 4 5 8 9
stdout
2