fork download
  1. #include<iostream>
  2. #include<vector>
  3. #include<algorithm>
  4. using namespace std;
  5.  
  6. int main(){
  7. int n;
  8. cin>>n;
  9. string *arr=new string[n];
  10. for(int i=0;i<n;i++){
  11. cin>>arr[i];
  12. }
  13.  
  14. int max=0;
  15. vector<string> sv;
  16. for(int i=0;i<n;i++){
  17. int count=0;
  18. for(int j=i;j<n;j++){
  19. if(arr[i]==arr[j]){
  20. count++;
  21. }
  22. }
  23. if(count>max){
  24. max=count;
  25. if(sv.size()==0){
  26. sv.push_back(arr[i]);
  27. }
  28. else{
  29. vector<string> sv;
  30. sv.push_back(arr[i]);
  31. }
  32. }
  33. else if(count==max){
  34. sv.push_back(arr[i]);
  35. }
  36. else{
  37. continue;
  38. }
  39. }
  40.  
  41. sort(sv.begin(),sv.end());
  42.  
  43. cout<<sv[0];
  44. }
Success #stdin #stdout 0.01s 5280KB
stdin
3
top
down
down
stdout
top