fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. int main()
  4. {
  5. unordered_map<int,int>mp;
  6. int n=8;
  7. int arr[]={4,2,6,4,2,5,6,2};
  8. for(int i=0;i<n;++i)
  9. {
  10. mp[arr[i]]++;
  11. }
  12. for(auto &ele:mp)
  13. {
  14. cout<<"Occurence of "<<ele.first <<" = "<<ele.second<<endl;
  15. }
  16.  
  17.  
  18. return 0;
  19. }
Success #stdin #stdout 0s 16064KB
stdin
Standard input is empty
stdout
Occurence of 5 = 1
Occurence of 6 = 2
Occurence of 2 = 3
Occurence of 4 = 2