IMohammedNasr

Untitled

Apr 22nd, 2022 (edited)
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.61 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. #define cin(v)        \
  4.     for (auto &i : v) \
  5.         cin >> i;
  6. #define cout(v)       \
  7.     for (auto &i : v) \
  8.         cout << i << " ";
  9. #define br cout << '\n';
  10. #define ll long long
  11. #define ull unsigned long long
  12. #define all(v) v.begin(), v.end()
  13. #define rall(v) v.rbegin(), v.rend()
  14. #define MOD 1000000007
  15. #define Time cerr << "Time Taken: " << (float)clock() / CLOCKS_PER_SEC << " Secs" \
  16.                   << "\n";
  17.  
  18. void Warding()
  19. {
  20.     ios_base::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);
  21. #ifndef ONLINE_JUDGE
  22.     freopen("input.txt", "r", stdin), freopen("output.txt", "w", stdout);
  23. #endif
  24. }
  25. bool is_prime(int n)
  26. {
  27.     if (n <= 1)
  28.         return false;
  29.     for (int i = 2; i <= sqrt(n); i++)
  30.         if (n % i == 0)
  31.             return false;
  32.     return true;
  33. }
  34.  
  35. void solve()
  36. {
  37.     int a = 0, b = 0;
  38.     string s;
  39.     cin >> s;
  40.     for (int i = 0; i < s.length(); i++)
  41.     {
  42.         if (s[i] == 'a')
  43.         {
  44.             a++;
  45.             if (b % 2 % 3 and b % 3 % 2 )
  46.             {
  47.                 cout << "NO" << '\n';
  48.                 return;
  49.             }
  50.             b = 0;
  51.         }
  52.         else
  53.         {
  54.             b++;
  55.             if (a % 2 % 3 and a % 3 % 2 )
  56.             {
  57.                 cout << "NO" << '\n';
  58.                 return;
  59.             }
  60.             a = 0;
  61.         }
  62.     }
  63.     cout << ((a % 2 % 3 and a % 3 % 2 ) or (b % 2 % 3 and b % 3 % 2) ? "NO" : "YES") << '\n';
  64. }
  65.  
  66. int main()
  67. {
  68.     Warding();
  69.     int t = 1;
  70.     cin >> t;
  71.     while (t--)
  72.     {
  73.         solve();
  74.     }
  75.     Time
  76. }
Add Comment
Please, Sign In to add comment