fork download
  1. #include<iostream>
  2. #include<unordered_map>
  3. using namespace std;
  4.  
  5. int main(){
  6.  
  7. int n;
  8. cin>>n;
  9.  
  10. int arr[n];
  11. for(int i=0; i<n; i++){
  12. cin>>arr[i];
  13. }
  14.  
  15. unordered_map<int, int> mp;
  16.  
  17. for(int i=0; i<n; i++){
  18. mp[arr[i]]++;
  19. }
  20.  
  21.  
  22. for(auto x: mp){
  23. cout<<x.first<<": "<<x.second<<endl;
  24. }
  25.  
  26. return 0;
  27. }
Success #stdin #stdout 0.01s 5288KB
stdin
5
1 2 1 2 1
stdout
2: 2
1: 3