NO
思路:
条件一最基本,先忽略。条件二,xPATx 就是正确的形式;在此基础上,如果 aPbTc 是正确的,那么 aPbATca 也是正确的。如果二者放在一起考虑,就是中间每增加一个A,后面就增加一个a,似乎数学关系出来了。我们知道aPbTc中a b c 段都只能包含“A",其长度分别为len(a)、len(b)、len(c),则其关系满足len(a)*len(b) = len(c)!这完美的契合了条件二与条件三,xPATx 就是当len(b) = 1,(a=x,c=c,b=A)的情况,在此基础上演化到条件三B中每增加一个A,c中相应增加一段”a“以上的乘法关系式成立。
//Java代码实现
import java.util.Scanner;
public class Main{
public static void main(String[] args){
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
sc.nextLine();
for(int i = 0 ;i < n ;i++){
String s = sc.nextLine();
String news = s;
if(news.contains("P")&&news.contains("A")&&news.contains("T")){
news = news.replace("A", "");
news = news.replace("P", "");
news = news.replace("T", "");
news = news.replace("\\s+", "");
if(news.isEmpty()){
int p = s.indexOf("P");
int t = s.indexOf("T");
int len = s.length();
int b = t - p - 1;
int c = len - t - 1;
if(p*b == c){
System.out.println("YES");
}else{
System.out.println("NO");
}
}else{
System.out.println("NO");
}
}else{
System.out.println("NO");
}
}
}
}