Advertisement
Emiliatan

e148

May 5th, 2019
164
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.53 KB | None | 0 0
  1. /* e148             */
  2. /* AC (57ms, 2.2MB) */
  3. #include <iostream>
  4. #include <string>
  5.  
  6. using namespace std;
  7.  
  8. int T, ans;
  9. string s;
  10.  
  11. int main()
  12. {
  13.     ios::sync_with_stdio(false);
  14.     cin.tie(0), cout.tie(0);
  15.  
  16.     cin >> T;
  17.     while (T--)
  18.     {
  19.         cin >> s;
  20.         s.push_back('z' + 1);
  21.         ans = 0;
  22.  
  23.         for (int i = 1; i < s.size() - 1;)
  24.         {
  25.             int l = 0;
  26.             while (s[ans + l] == s[i + l]) ++l;
  27.             if (s[ans + l] > s[i + l]) swap(ans, i);
  28.             i += l + 1;
  29.             if (i == ans) ++i;
  30.         }
  31.         cout << ans + 1 << '\n';
  32.     }
  33.     return 0;
  34. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement