import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int len = Integer.parseInt(in.nextLine());
String[] strings = new String[len];
for (int i = 0; i < len; i++) {
strings[i] = in.nextLine();
}
int k;
boolean flag;
for (String s : strings) {
k = 0;
flag = true;
int[] a = new int[3];
char[] chars = s.toCharArray();
for (char ch : chars) {
if (ch == ‘A‘) {
a[k]++;
} else if (ch == ‘P‘ && k == 0) {
k = 1;
} else if (ch == ‘T‘ && k == 1) {
k = 2;
} else {
flag = false;
}
}
/**
* 包含的每个字符必须是p a t中的某一个
* p在t前
* p t各一个,至少一个a
* n0*n1=n2
*/
if (flag && k == 2 && a[1] >= 1 && a[0] * a[1] == a[2]) {
System.out.println("YES");
} else {
System.out.println("NO");
}
}
}
}
原文:https://www.cnblogs.com/zxqSS/p/12264846.html