Pure Code:
AC代码
#include <iostream>
#include <cstring>
#include <cmath>
using namespace std;int main() {
int n;cin>>n;char string[100];while(n--){
cin>>string;//std::cout << string <<" "<<strlen(string) << std::endl;int count_left = 0,count_middle = 0,count_right = 0;int Pos_p=-1,Pos_a=-1,Pos_t=-1;bool flag = true;for(int i=0;i<strlen(string);i++){
if(string[i]!='P'&&string[i]!='A'&&string[i]!='T') {
cout<<"NO"<<endl;flag = false;break;}if(string[i]=='P') Pos_p = i;if(string[i]=='A') Pos_a = i;if(string[i]=='T') Pos_t = i;}if(!flag) {
continue;}if(Pos_p > Pos_t||abs(Pos_t - Pos_p)==1) {
cout<<"NO"<<endl;continue;}if(Pos_p== -1 ||Pos_a == -1|| Pos_t == -1) {
cout<<"NO"<<endl; continue;}else{
count_left = Pos_p - 0;count_middle = Pos_t- Pos_p -1;count_right = strlen(string) - Pos_t - 1;//cout<<count_left<<" "<<count_middle<<" "<<count_right<<endl;}if((count_left*count_middle)!=count_right) {
cout<<"NO"<<endl;continue;}cout<<"YES"<<endl;}return 0;
}