1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50
| #include <bits/stdc++.h> using namespace std;
const int N = 1001;
int T; string s; int hzl[N]; int hzx[N];
int main() { cin >> T; while (T--) { cin >> s; memset(hzl, 0, sizeof(hzl)); memset(hzx, 0, sizeof(hzx)); for (int i = s.size()-1; i >= 0; i--) { hzl[i] = hzl[i+1] + (s[i] == 'l'); hzx[i] = hzx[i+1] + (s[i] == 'x'); } int cnt = 0, pre = 0; int ans = 1e9+7; for (int i = 0; i < s.size(); i++) { if (s[i] == 'l') { continue; } cnt++; if (cnt == 3) { if(hzl[i] <= 1) { ans = min(ans, pre); break; } else { ans = min(ans, pre+hzl[i]-1); ans = min(ans, pre+hzx[i]); } cnt--; pre++; } } if (ans == 1e9+7) { ans = 0; } cout << ans << endl; }
return 0; }
|