D. BQG's Random String
Time Limit: 2000ms
Memory Limit: 32768KB
64-bit integer IO format:
%lld Java class name:
Main
“Vim是一个类似于Vi的著名的功能强大、高度可定制的文本编辑器,在Vi的基础上改进和增加了很多特性。”——百度百科
但是初学要上手Vim并不是一件容易的事……问:如何生成一个随机的字符串?答:让新手退出Vim……
![Big \ Q \ God Big \ Q \ God](http://www.bnuoj.com/v3/functions/latexrender/pictures/452ca35779267682d31b87da49b2a42e.png)
所谓“子串”,是指在原字符串中取出一个连续片段得到的新字符串,比如"BAB"是"ABABC"的子串,但是"AAC"不是。
Input
第一行是一个正整数
,表示测试数据的组数,
![T(T \leq 1000) T(T \leq 1000)](http://www.bnuoj.com/v3/functions/latexrender/pictures/924f04bd617eb7fdbf7c5366099c5192.png)
每组测试数据只有一行,
包含一个长度
且只包含大写字母的非空字符串。
![\leq 10000 \leq 10000](http://www.bnuoj.com/v3/functions/latexrender/pictures/60a3e7cc5fc443e6b2e957ee7147775f.png)
Output
对于每组测试数据,输出一个整数,表示字符串中子串"QAQ"的个数。
Sample Input
5 Q QAQ QAQAQ QQQQQQQ QAQABCDEF
Sample Output
0 1 2 0 1
#include<stdio.h>
#include<string.h>
#include<iostream>
#include<stdlib.h>
#include<algorithm>
using namespace std;
int main(){
int T;
char s[100000];
cin>>T;
while(T--){
int cnt=0;
int i,j,k;
scanf("%s",s);
int len=strlen(s);
for(i=0;i<len;i++){
if(s[i]!='Q')
continue;
for(j=i+1;j<len;j++){
if(s[j]!='A'){
break;
}else{
if(s[j]=='A'&&s[j+1]=='Q'){
cnt++;
}else{
break;
}
}
}
}
cout<<cnt<<endl;
}
return 0;
}