fork download
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. int main(){
  4. int n;
  5. cin>>n;
  6.  
  7. vector<int> arr(n,0);
  8. unordered_map<int,int>mpp;
  9.  
  10. for(int i = 0;i<n;i++){
  11. cin>>arr[i];
  12.  
  13.  
  14. }
  15.  
  16. for(int i = 0;i<n;i++){
  17. mpp[arr[i]]++;
  18. }
  19.  
  20. int maxi=INT_MIN, maxiEle = 0;
  21. for(auto &it: mpp){
  22. int freq = it.second;
  23. if(freq > maxi){
  24. freq = maxi;
  25. maxiEle = it.first;
  26. }
  27. }
  28.  
  29. cout<<"The maximum frequency of number is:"<<maxiEle<<endl;
  30.  
  31.  
  32.  
  33. return 0;
  34. }
Success #stdin #stdout 0.01s 5284KB
stdin
5
1
2
2
2
3
stdout
The maximum frequency of number is:2