fork download
  1. #include <iostream>
  2. #include<vector>
  3. #include<unordered_map>
  4. using namespace std;
  5.  
  6. int main() {
  7. // your code goes here
  8. vector<int> arr={1,1,1,2,2,3,3,4};
  9.  
  10. unordered_map<int,int> m;
  11. for(int i=0;i<arr.size();i++) {
  12. m[arr[i]]++;
  13. }
  14.  
  15. for (auto it = m.begin(); it != m.end(); it++) {
  16. cout << it->first << " -> " << it->second << endl;
  17. }
  18. return 0;
  19. }
Success #stdin #stdout 0.01s 5288KB
stdin
Standard input is empty
stdout
4 -> 1
3 -> 2
1 -> 3
2 -> 2