题意:求有多少个连续子串只含'q'字符。
分析:求出所有以'q'为开头的子串即可。
代码:
#include<map>
#include<set>
#include<stack>
#include<cmath>
#include<queue>
#include<bitset>
#include<math.h>
#include<vector>
#include<string>
#include<stdio.h>
#include<cstring>
#include<iostream>
#include<algorithm>
#pragma comment(linker, "/STACK:102400000,102400000")
using namespace std;
typedef double db;
typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;
const db eps=1e-5;
const int N=1e5+10;
const int M=1e5+10;
const ll MOD=1000000007;
const int mod=1000000007;
const int MAX=1000000010;
const double pi=acos(-1.0);
char s[N];
int main()
{
int i,T,len,now,last;
ll ans;
scanf("%d", &T);
while (T--) {
scanf("%s", s);
len=strlen(s);
now=last=0;ans=0;
for (i=len-1;i>=0;i--)
if (s[i]=='q') now=++last,ans+=(ll)now;
else last=0;
printf("%lld\n", ans);
}
return 0;
}