Advertisement
Guest User

Untitled

a guest
Apr 7th, 2020
143
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.08 KB | None | 0 0
  1. #include <iostream>
  2. #include <map>
  3. #include <string>
  4. #include <vector>
  5.  
  6. using namespace std;
  7.  
  8. bool u (string e, string q)
  9. {
  10.     for(int i = 0; i < min(e.size(), q.size()); i++)
  11.     {
  12.         if(e[i] > q[i])
  13.         {
  14.             return true;
  15.         }
  16.         else if(e[i] < q[i])
  17.         {
  18.             return false;
  19.         }
  20.     }
  21.     if(e.size() > q.size())
  22.         return false;
  23.     else
  24.     {
  25.         return true;
  26.     }
  27. }
  28.  
  29. int main()
  30. {
  31.     string a;
  32.     getline(cin, a);
  33.     a += " ";
  34.     map < string, int > m;
  35.     int ma = -99999;
  36.     string mas;
  37.     string w = "";
  38.     for(int i = 0; i < a.size(); i++)
  39.     {
  40.         if(a[i] == ' ')
  41.         {
  42.             m[w]++;
  43.             if(m[w] > ma)
  44.             {
  45.                 ma = m[w];
  46.                 mas = w;
  47.             }
  48.             if(m[w] == ma)
  49.             {
  50.                 if(u(mas, w))
  51.                 {
  52.                     mas = w;
  53.                 }
  54.             }
  55.             w = "";
  56.         }
  57.         else
  58.         {
  59.             w += a[i];
  60.         }
  61.     }
  62.     cout << mas;
  63. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement