fork download
  1. #include <iostream>
  2. #include <bits/stdc++.h>
  3. using namespace std;
  4.  
  5. int main() {
  6. // your code goes here
  7. int n ; cin>>n;
  8. vector<int>arr(n);
  9. for(int i = 0 ; i<n;i++){
  10. cin>>arr[i];
  11. }
  12. unordered_map<int,int>mp;
  13. for(int i = 0 ; i<n;i++){
  14. mp[arr[i]]++;
  15. }
  16. for(auto &p : mp){
  17. cout<<"element "<<p.first<<" "<<"frequency "<<p.second<<"\n";
  18. }
  19. return 0;
  20. }
Success #stdin #stdout 0s 5316KB
stdin
8 
1 1 2 3 1 4 4 2
stdout
element 4 frequency 2
element 3 frequency 1
element 1 frequency 3
element 2 frequency 2