-
Notifications
You must be signed in to change notification settings - Fork 2
/
B1003.cpp
50 lines (48 loc) · 971 Bytes
/
B1003.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#include <cstdio>
#include <cstring>
bool judge(char s[], int len){
int posP = -1, posT = -1, midA = 0;
for(int i = 0; i < len; ++i){
if(s[i] == 'A'){
if(posP != -1 && posT == -1){
++midA;
}
}else if(s[i] == 'P' && posP == -1){
posP = i;
}else if(s[i] == 'T' && posT == -1){
posT = i;
}else{
return false;
}
}
/*if(posP == -1 || posT == -1 || midA == 0) return false;
if(posT - posP + 1 == 3 && posP == len - 1 - posT) return true;
//int midA = posT - posP - 2;
//if(posT - midA < 0) return false;
s[posT] = 'A';
s[posT-1] = 'T';
len -= (posP + 1) * 1;
if(len < 3) return false;
return judge(s, len);*/
int x = posP, y = posT - posP - 1, z = len - posT - 1;
if(z-x*(y-1) == x && y > 0){
return true;
}else{
return false;
}
}
int main(){
int n;
scanf("%d", &n);
while(n--){
char s[110];
scanf("%s", s);
int len = strlen(s);
if(judge(s, len)){
printf("YES\n");
}else{
printf("NO\n");
}
}
return 0;
}