不得不说这题我也卡了好久,是看了一个大佬的解析才恍然大悟的,a*b=c这个等式非常重要
#include<stdio.h>
int judge(char str[]);
int main(int argc,char const*argv[])
{
char str[999][999];
int n;
scanf("%d",&n);
for(int i=0;i<n;i++){
scanf("%s",&str[i]);
}
int x;
for(int p=0;p<n;p++){
x=judge(str[p]);
if(x==1){
printf("YES\n");
}else if(x==-1){
printf("NO\n");
}
}
return 0;
}
int judge(char str[]){
int cnt1=0;
int cnt2=0;
int cnt3=0;
int s=0;
int t=0;
int q=0;
int a,b,c;
for(int i=0;str[i]!='\0';i++){
if(str[i]!='P'&&str[i]!='A'&&str[i]!='T'){
return -1;
}
}
for(int i=0;str[i]!='\0';i++){
if(str[i]=='P'){
cnt1++;
}
if(str[i]=='T'){
cnt2++;
}
if(str[i]=='A'){
cnt3++;
}
}
if(cnt1!=1|cnt2!=1|cnt3==0){
return -1;
}
while(str[s]!='P'){
s++;
}
while(str[t]!='T'){
t++;
}
if(s+1>=t){
return -1;
}
while(str[q]!='\0'){
q++;
}
a=s;
b=t-s-1;
c=q-t-1;
if(a*b==c){
return 1;
}else{
return -1;
}
}