B 苦逼的单身狗
来源:https://www.cnblogs.com/RE-TLE/p/11447306.html
我在里面增加了输出如何截取的代码, 取消注释以后运行即可,这样或许更好理解了代码的做法
#include <iostream> #include<cstdlib> #include<cstdio> using namespace std; const int n = 9; char t[n]; int main() { int T; cin >> T; while (T--) { cin >> t; int L = strlen(t); long long ans = 0; int l = -1, o = -1, v = -1, e = -1, d = 0; for (int i = 0;i < L; i++) { if (t[i] == 'L') l = i; else if (t[i] == 'O') o = i; else if (t[i] == 'V') v = i; else if (t[i] == 'E') e = i; d = min(min(l, o), min(v, e)); if (d != -1) ans += d + 1; //截取的字符串文本如下: /*for (int j = 0;j <= d;j++) { for (int m = j;m <= i;m++) { cout << t[m]; } cout << endl; }*/ } cout << ans << endl; } return 0; }