fork(1) download
  1. #include <iostream>
  2. #include <unordered_map>
  3.  
  4. using namespace std;
  5.  
  6. int main()
  7. {
  8. int test_data[] {1, 2, 2, 5, 2, 5, 9, 9, 9};
  9.  
  10. unordered_map<int, int> count_dict;
  11. for (int i : test_data)
  12. count_dict[i]++;
  13.  
  14. int max_count=0;
  15. int idx=0;
  16. int result[sizeof(test_data)/sizeof(test_data[0])];
  17. for(const auto &pair:count_dict)
  18. {
  19. if(max_count<pair.second)
  20. {
  21. max_count=pair.second;
  22. idx=0;
  23. result[idx++]=pair.first;
  24. }
  25. else if(max_count==pair.second)
  26. result[idx++]=pair.first;
  27. }
  28.  
  29. for(int i=0;i<idx;i++)
  30. cout << result[i] <<endl;
  31. }
Success #stdin #stdout 0s 16064KB
stdin
Standard input is empty
stdout
9
2