Advertisement
a53

NrMinMaxAp

a53
Jun 18th, 2021
229
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.52 KB | None | 0 0
  1. int NrMinMaxAp(vector<int> &a)
  2. {
  3. map<int, int> M;
  4. int maxfr=0, minnr=INT_MAX;
  5. for(int i=0; a[i]; i++)
  6. {
  7. if(M.find(a[i]) == M.end())
  8. M[a[i]] = 1;
  9. else
  10. {
  11. M[a[i]]++;
  12. if(M[a[i]]>maxfr)
  13. {
  14. maxfr=M[a[i]];
  15. minnr=a[i];
  16. }
  17. else if(M[a[i]]==maxfr)
  18. {
  19. if(a[i]<minnr)
  20. minnr=a[i];
  21. }
  22. }
  23. }
  24. return minnr;
  25. }
  26.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement