fork(1) download
  1. #include <iostream>
  2. #include <map>
  3.  
  4. int main()
  5. {
  6. std::map<int, std::size_t> counts;
  7. int x;
  8. while(std::cin >> x)
  9. {
  10. ++counts[x]; //or: counts[x] = counts[x] + 1;
  11. }
  12. std::multimap<std::size_t, int> mode;
  13. for(auto const &v : counts)
  14. {
  15. mode.emplace(v.second, v.first);
  16. }
  17. auto most = mode.rbegin()->first;
  18. std::cout << "Appearing " << most << " times: ";
  19. for(auto it = mode.rbegin(); it != mode.rend() && it->first == most; ++it)
  20. {
  21. std::cout << it->second << " ";
  22. }
  23. std::cout << std::endl;
  24. }
  25.  
Success #stdin #stdout 0s 3236KB
stdin
1 2 2 2 3 3 3
stdout
Appearing 3 times: 3 2