fork download
  1. #include <iostream>
  2. #include <vector>
  3. #include <algorithm>
  4. #include <unordered_map>
  5.  
  6. template <typename T>
  7. using CounterMap = std::unordered_map<T, std::size_t>;
  8.  
  9. int main() {
  10. std::vector<int> vec = {1, 2, 3, 3, 2, 1, 1, 2, 3, 3};
  11.  
  12. CounterMap<int> counter;
  13.  
  14. for (int value : vec) {
  15. ++counter[value];
  16. }
  17.  
  18. std::cout << max_element(counter.begin(),
  19. counter.end(),
  20. [](const CounterMap<int>::value_type &lhs,
  21. const CounterMap<int>::value_type &rhs) {
  22. return lhs.second < rhs.second;
  23. })->first;
  24. return 0;
  25. }
Success #stdin #stdout 0s 3032KB
stdin
Standard input is empty
stdout
3