fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. int main() {
  5. // your code goes here
  6. int a[]={3,2,3,2,4,3};
  7. int n=sizeof(a)/sizeof(a[0]);
  8. unordered_map<int,int>m;
  9. for(int i=0;i<n;i++){
  10. m[a[i]]++;
  11. }int maxi=0;
  12. int mini=1e9;
  13. int maxel=0;
  14. int minel=0;
  15. for(int i=0;i<n;i++){
  16. if(m[a[i]]>maxi){
  17. maxi=m[a[i]];
  18. maxel=a[i];
  19. }
  20. if(m[a[i]]<mini){
  21. mini=m[a[i]];
  22. minel=a[i];
  23. }
  24.  
  25. }
  26. cout<<maxel<<"-"<<maxi<<endl;
  27. cout<<minel<<"-"<<mini<<endl;
  28. return 0;
  29. }
Success #stdin #stdout 0.01s 5324KB
stdin
Standard input is empty
stdout
3-3
4-1