fork download
  1. #include <map>
  2. #include <iostream>
  3.  
  4. int main() {
  5. std::map<int, int> freqs;
  6. int num;
  7. while(std::cin >> num) {
  8. freqs[num]++; //this works because int values start at 0 inside of maps
  9. }
  10. for(auto it = freqs.begin(); it != freqs.end(); it++) {
  11. std::cout << it->first << " occurred " << it->second << " times." << std::endl;
  12. }
  13. return 0;
  14. }
  15.  
Success #stdin #stdout 0s 3236KB
stdin
5
6
12
22
33
4
5
6
-8
90
-27
5
5
5
5
stdout
-27 occurred 1 times.
-8 occurred 1 times.
4 occurred 1 times.
5 occurred 6 times.
6 occurred 2 times.
12 occurred 1 times.
22 occurred 1 times.
33 occurred 1 times.
90 occurred 1 times.