题目链接http://acm.hdu.edu.cn/showproblem.php?pid=5907
思路
尺取法,要注意结果会超出int范围
#include<stdio.h>
#include<iostream>
#include<string.h>
#define ll long long
using namespace std;
char s[100010];
int main(){
int t;
for(scanf("%d",&t);t--;){
memset(s,0,sizeof(s));
scanf("%s",s);
int len=strlen(s);
ll cnt=0;
for(int i=0;i<len;){
if(s[i]=='q'){
ll c=1; //用int c就错了,当时就错在这
while(s[i+c]=='q'){
c++;
}
cnt+=c*(c+1)/2;
i+=c;
}
else
i++;
}
printf("%lld\n",cnt);
}
return 0;
}