#include<iostream>
#include<string>
using namespace std;
int main(){
int n=0;
cin>>n;
int flagerror=0;
for(int j=0;j<n;j++)
{
flagerror=0;
getchar();
string str;
cin>>str;
int FlagP=0,FlagT=0,FlagA=0,countP=0,countT=0,countA=0;
int i=0;
for(;str[i]!='\0';i++)
{
if(str[i]!='A' && str[i]!='P' && str[i]!='T')
{
cout<<"NO"<<endl;
flagerror=1;
break;
}
if(str[i]=='P')
{
FlagP=i;
countP++;
}
if(str[i]=='A')
{
FlagA=i;
countA++;
}
if(str[i]=='T')
{
FlagT=i;
countT++;
}
}
if(flagerror==1)
{
continue;
}
if(countT>1 || countP>1||countA==0||countT==0||countP==0||FlagT==FlagP+1||FlagT<FlagP)
{
cout<<"NO"<<endl;
continue;
}
int t=FlagT-FlagP-1;
if(t>1)
{
if(FlagP==0)
{
;
}
else{
if(i-FlagT-1!=FlagP*t)
{
cout<<"NO"<<endl;
continue;
}
}
}
if(t==1)
{
if(FlagP!=i-FlagT-1)
{
cout<<"NO"<<endl;
continue;
}
}
cout<<"YES"<<endl;
}
}
错误:1.计算公式。为避免这种情况:画图、用文字写完公式再用字母表达。让代码中的字母与草稿纸上的字母表示的东西一样。
2.注意输出是否与代码中的一致。例如题目中是“答案正确、答案错误”,但输出是“YES”、“NO”。
3.判断特殊情况是否正确