fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. int main() {
  5. vector<int> arr={3,2,3,3,2,4};
  6. map<int,int> ok;
  7. for(int i=0;i<arr.size();i++){
  8. ok[arr[i]]++;
  9. }
  10. int maxl,minl,max=-1,min=0;
  11. for(auto it=ok.begin();it!=ok.end();it++){
  12. cout<<it->first<<" "<<it->second<<endl;
  13. if(it->second>max){
  14. max=it->second;
  15. maxl=it->first;
  16. }
  17. if(it->second < min){
  18. min=it->second;
  19. minl=it->first;
  20. }
  21. }
  22. cout<<"maxelement "<<maxl<<" freq "<<max;
  23. cout<<"minelement "<<minl<<" freq "<<min;
  24. return 0;
  25. }
Success #stdin #stdout 0s 5320KB
stdin
Standard input is empty
stdout
2  2
3  3
4  1
maxelement  3  freq  3minelement   72703    freq  0