fork download
  1. // most frequently string that later lexiographically
  2. #include <bits/stdc++.h>
  3. using namespace std;
  4.  
  5. int main() {
  6. int T;
  7. cin>>T;
  8. string arr[T];
  9. for(int i=0;i<T;i++){
  10. cin>>arr[i];
  11. }
  12. map<string,int> mp;
  13. int mxcount=-1;
  14.  
  15. for(int i=0;i<T;i++){
  16. mp[arr[i]]++;
  17. mxcount=max(mxcount,mp[arr[i]]);
  18. }
  19. sort(arr,arr+T);
  20.  
  21. for(int i=T-1;i>0;i--){
  22. if(mp[arr[i]]==mxcount){
  23. cout<<arr[i]<<" "<<mp[arr[i]];
  24. break;
  25. }
  26. }
  27. return 0;
  28. }
Success #stdin #stdout 0s 5528KB
stdin
10
mountain
lake
lake
zebra
tree
lake
zebra
zebra
animal
lakes
stdout
zebra 3