fork(1) download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. // Speed
  5. #define fast_io ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)
  6.  
  7. // Typedefs
  8. #define int long long
  9. #define pb push_back
  10. #define ff first
  11. #define ss second
  12. #define all(x) (x).begin(), (x).end()
  13. #define rall(x) (x).rbegin(), (x).rend()
  14. #define sz(x) ((int)(x).size())
  15. #define endl '\n'
  16.  
  17. // Loops
  18. #define rep(i,a,b) for(int i=a;i<b;++i)
  19. #define per(i,a,b) for(int i=b-1;i>=a;--i)
  20. #define each(x, a) for (auto& x : a)
  21.  
  22. // Consts
  23. const int INF = 1e18;
  24. const int MOD = 1e9+7;
  25. const int N = 2e5 + 5;
  26.  
  27. // Math
  28. int gcd(int a, int b) { return b == 0 ? a : gcd(b, a % b); }
  29. int lcm(int a, int b) { return (a / gcd(a, b)) * b; }
  30.  
  31. int power(int a, int b, int m = MOD) {
  32. int res = 1;
  33. while (b > 0) {
  34. if (b & 1) res = res * a % m;
  35. a = a * a % m;
  36. b >>= 1;
  37. }
  38. return res;
  39. }
  40.  
  41. int modinv(int a, int m = MOD) {
  42. return power(a, m - 2, m);
  43. }
  44.  
  45. // Logic
  46. void solve() {
  47. string r;
  48. cin >> r;
  49. int n = r.size();
  50.  
  51. vector<int> s_pos;
  52. int total_u = 0;
  53.  
  54. for (int i = 0; i < n; i++) {
  55. if (r[i] == 's') s_pos.pb(i);
  56. else total_u++;
  57. }
  58.  
  59. if (sz(s_pos) < 2) {
  60. cout << total_u << endl;
  61. return;
  62. }
  63.  
  64. int allowed_u = 0;
  65.  
  66. for (int i = 0; i + 1 < sz(s_pos); i++) {
  67. int L = s_pos[i];
  68. int R = s_pos[i + 1];
  69. int d = R - L - 1;
  70.  
  71. if (d % 2 == 0 && d > 0) {
  72. int mid = (L + R) / 2;
  73. if (r[mid] == 'u') allowed_u++;
  74. }
  75. }
  76.  
  77. cout << total_u - allowed_u << endl;
  78. }
  79.  
  80. // Main
  81. int32_t main() {
  82. fast_io;
  83.  
  84. int t;
  85. cin >> t;
  86. while (t--) {
  87. solve();
  88. }
  89.  
  90. return 0;
  91. }
  92.  
Success #stdin #stdout 0.01s 5288KB
stdin
9
sus
uuuu
sssss
uusuuu
suuuuuu
usssssss
sssuuusss
susuusuuus
uuuuuuuuuuu
stdout
1
4
0
5
6
1
3
5
11