#include<stdio.h>
#include<string.h>
void judge(char *str,int a);
main(){
char ch[10][100];
int n;
int i;
int str_num;
n = 0;
scanf("%d",&n);
for(i=1;i<=n;i++){
scanf("%s",&ch[i][0]);
}
for(i=1;i<=n;i++){
str_num=strlen(ch[i]);
judge(&ch[i][0],str_num);
}
return 0;
}
void judge(char *str,int a){
int i,z,c,a_,num_p,num_t;
int spot_p,spot_t;
a_ = 0;
spot_p = 0;
spot_t = 0;
z = 0;
num_p=0;
num_t=0;
for(i=0;i<=(a-1);i++,str++){
if(*str=='P'){
num_p++;
spot_p=i+1;
}
if(*str=='T'){
num_t++;
spot_t=i+1;
}
if(*str=='A'){
a_++;
}
}
if ( ((num_p+a_+num_t<a)) || (num_p>1) || (num_t>1) || ((spot_p-1)*(spot_t-spot_p-1)!=(a-spot_t)) || ((spot_t-spot_p)<=1)){
printf("NO\n");
}
else {
printf("YES\n");
}
}
这题参考了网上的思路。P前面的a乘P和T中间的a等于T后面a的数量,这是最关键的点,如果没有这个,光靠题目给的例子,可以拿15分。
剩下的条件就是P 和 T只有一个,并且P和T中间一定有A,所以前面可以当做两个条件。
剩下就是,如果三个数加起来不等于总字符串的长度,说明就有别的东西在你的字符串了。可以直接写NO。