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. vector<bool>vis(n);
  13. int count ;
  14. for(int i =0;i<n;i++){
  15. if(!vis[i]){
  16. count =1;
  17. for(int j =i+1;j<n;j++){
  18. if(arr[i]==arr[j]){
  19. count++;
  20. vis[j]=true;
  21. }
  22. }
  23. cout<<"frequency of" << arr[i] << "is" << count<<endl;
  24. }
  25.  
  26.  
  27. }
  28.  
  29.  
  30. return 0;
  31. }
Success #stdin #stdout 0s 5316KB
stdin
8
1 2 5 1 5 4 2 1
stdout
frequency of1is3
frequency of2is2
frequency of5is2
frequency of4is1