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. int total_u = 0;
  52. for (char c : r) if (c == 'u') total_u++;
  53.  
  54. int max_u = (n - 2) / 2;
  55. if (max_u < 0) max_u = 0;
  56.  
  57. int kept_u = min(total_u, max_u);
  58. cout << total_u - kept_u << endl;
  59. }
  60.  
  61. // Main
  62. int32_t main() {
  63. fast_io;
  64.  
  65. int t;
  66. cin >> t;
  67. while (t--) {
  68. solve();
  69. }
  70.  
  71. return 0;
  72. }
  73.  
Success #stdin #stdout 0.01s 5320KB
stdin
9
sus
uuuu
sssss
uusuuu
suuuuuu
usssssss
sssuuusss
susuusuuus
uuuuuuuuuuu
stdout
1
3
0
3
4
0
0
2
7