-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpat1003.cpp
66 lines (57 loc) · 1.2 KB
/
pat1003.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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
/*
* first.cpp
*
* Created on: 2015年2月5日
* Author: thomas
*/
#include <iostream>
#include <string>
using namespace std;
class check{
public:
check(string s):checkstring(s){}
check()=default;
bool firstRule(const string& s);
bool secondRule(const string& s);
void assignment(string s){checkstring=s;}
private:
string checkstring;
};
bool check::firstRule(const string& s){
for(auto i:s){
if(i!='P'&&i!='A'&&i!='T')
return false;
}
return true;
}
bool check::secondRule(const string& s){
auto i=s.begin();
auto j=s.end()-1;
while(*i!='P'){
if(*i!='A'||i==s.end()-1)return false;
++i;
}
while(*j!='T'){
if(*j!='A'||j==s.begin())return false;
--j;
}
auto firstA=i-s.begin();
auto lastA=s.end()-j-1;
auto middleA=j-i-1;
if(lastA==middleA*firstA&&middleA!=0)return true;
else return false;
}
int main(){
int i;
cin>>i;
check c;
string s;
for(int j=0;j<i;j++){
cin>>s;
c.assignment(s);
if(!c.firstRule(s))cout<<"NO"<<endl;
else if(!c.secondRule(s))cout<<"NO"<<endl;
else cout<<"YES"<<endl;
}
return 0;
}