-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path1003.cpp
More file actions
60 lines (56 loc) · 964 Bytes
/
1003.cpp
File metadata and controls
60 lines (56 loc) · 964 Bytes
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
51
52
53
54
55
56
57
58
59
60
#include<iostream>
#include<string>
using namespace std;
bool judge(string str){
int len=str.length();
if(len<=2)
return false;
bool book[3]={false};
for(int i=0;i<len;i++){
if(str[i]=='P')
book[0]=true;
else if(str[i]=='A')
book[1]=true;
else if(str[i]=='T')
book[2]=true;
else
return false;
if(str[i]=='P'){
for(int j = 0;j<i;j++){
if(str[j]!='A')
return false;
}
if(str[i+1]!='A')
return false;
for(int k=i+2;k<len;k++){
if(str[k]!='A'){
if(str[k]!='T')
return false;
if((len-k-1)!=((k-1-i)*i))
return false;
for(int m=k+1;m<len;m++){
if(str[m]!='A')
return false;
}
}
}
}
}
if(book[0]==false||book[1]==false||book[2]==false)
return false;
return true;
}
int main(){
int n;
cin >> n;
string s;
for(int i=0;i<n;i++){
cin>>s;
if(judge(s)==true)
cout<<"YES"<<endl;
else
cout <<"NO"<<endl;
}
system("pause");
return 0;
}