[HDU5907]Find Q(水)

时间:2021-06-02 15:49:28

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5907

记下每块大小,然后n*(n+1)/2

 #include <bits/stdc++.h>
using namespace std; typedef long long LL;
const int maxn = ;
char s[maxn];
vector<LL> ret; int main() {
// freopen("in", "r", stdin);
int T;
scanf("%d", &T);
while(T--) {
ret.clear();
scanf("%s", s);
int pos = ;
bool flag = ;
for(int i = ; s[i]; i++) {
if(s[i] == 'q') pos++;
else {
if(pos != ) ret.push_back(pos);
pos = ;
}
}
if(pos != ) ret.push_back(pos);
LL ans = ;
for(int i = ; i < ret.size(); i++) {
ans += ret[i]*(ret[i]+)/;
}
cout << ans << endl;
}
return ;
}