Naxocist

Untie

Apr 29th, 2023
1,006
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.74 KB | Source Code | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. using ll = long long int;
  4.  
  5. void solve() {
  6.     string s; cin >> s;
  7.     int n = s.size();
  8.     vector<int> range;
  9.     char t = '*';
  10.     int r = 0;
  11.  
  12.     for(char c : s) {
  13.         if(c != t) {
  14.             if(t != '*') range.push_back(r);
  15.             t = c;
  16.             r = 0;
  17.         }
  18.         r++;
  19.     }
  20.     range.push_back(r);
  21.     int m = range.size();
  22.     if(range.size() == 1) {
  23.         cout << (n + 1)/2 << '\n';
  24.     }else {
  25.         if(s[0] == s[n-1]) range[0] += range[m-1], range[m-1] = 0;
  26.         int res = 0;
  27.         for(int x : range) {
  28.             res += x/2;
  29.         }
  30.         cout << res << '\n';
  31.     }
  32. }
  33.  
  34. int main() {
  35.     cin.tie(nullptr)->sync_with_stdio(false);
  36.     int q; cin >> q;
  37.     for(int i=1; i<=q; ++i) {
  38.         cout << "Case #" << i << ": ";
  39.         solve();
  40.     }
  41.     return 0;
  42. }
  43.  
  44. /*
  45. PRSSP
  46. PRPSP
  47.  
  48. */
Advertisement
Add Comment
Please, Sign In to add comment