Hustlingbeast_Anish

Hustlingbeast_7

Mar 13th, 2022
129
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.00 KB | None | 0 0
  1.  
  2. #include <bits/stdc++.h>
  3. #include <algorithm>
  4. #define lli long long int
  5. #define li long int
  6. #define vi vector<int>
  7. #define mod 1000000007
  8. #define ld long double
  9. #define F first
  10. #define S second
  11. #define PB push_back
  12. #define MP make_pair
  13. #define REP(i, a, b) for (int i = a; i < b; i++)
  14. using namespace std;
  15.  
  16. int main()
  17. {
  18.     ios_base::sync_with_stdio(false);
  19.     cin.tie(NULL);
  20.  
  21.     lli t;
  22.     cin >> t;
  23.  
  24.     while (t--)
  25.     {
  26.         string s;
  27.         cin >> s;
  28.         lli p = s.size();
  29.         vi vec;
  30.         lli ct = 0;
  31.         for (lli i = 0; i < s.size(); i++)
  32.         {
  33.             if (s[i] != s[0] && s[i] != s[p - 1])
  34.             {
  35.                 ct++;
  36.             }
  37.             else
  38.             {
  39.                 ct = 0;
  40.             }
  41.             vec.PB(ct);
  42.         }
  43.         lli h = *max_element(vec.begin(), vec.end());
  44.         if (h == 0)
  45.         {
  46.             cout << -1 << endl;
  47.         }
  48.         else
  49.             cout << h << endl;
  50.     }
  51.     return 0;
  52. }
Advertisement
Add Comment
Please, Sign In to add comment