Find Q
Accepts: 392
Submissions: 780
Time Limit: 2000/1000 MS (Java/Others)
Memory Limit: 262144/131072 K (Java/Others)
本题想很好想,就是注意一下数据类型用 long long 型就好了,看似不超int 实则超int。
#include<cstdio>
#include<iostream>
#include<cstring>
#include<cmath>
#include<algorithm>
#define LL long long
using namespace std;
const int N = 100000+20;
char S[N];
int main(){
int T;
scanf("%d",&T);
while(T--){
scanf("%s",S);
LL cnt=0,ans=0;
int L=strlen(S);
for(int i=0;i<=L;i++){
if(S[i]=='q'){
cnt++;
}
else if(S[i]!='q'&&S[i-1]=='q'){
for(int j=cnt;j>=1;j--){
ans+=j;
}
cnt=0;
}
}
printf("%lld\n",ans);
}
return 0;
}