"Correct answer" is the most joy automatic reply sentence topic given system. This title belongs to the PAT of "correct answer" big delivery - just read the string following conditions are satisfied, the system will output "correct answer", otherwise outputs "Wrong Answer."
Get the "correct answer" conditions are:
- String must have only
P
,A
,T
three characters can not contain other characters; - Arbitrary shape such as
xPATx
a string can get "correct answer", whereinx
either the empty string, or only by the letterA
string thereof; - If you
aPbTc
are correct, thenaPbATca
it is correct, whicha
,b
,c
are either empty string, or only by the letterA
string composed.
Now ask you to write a PAT referee program automatically determines which strings can get "the answer right".
Input formats:
Each test comprises a test input. The first row is given a positive integer n-( <), the number is the character string to be detected. Next, one row for each string, the string length of not more than 100, no spaces.
Output formats:
The detection result row for each string, if the string can get "correct answer", the output YES
, otherwise the output NO
.
Sample input:
8
PAT
PAAT
AAPATAA
AAPAATAAAA
xPATx
PT
Whatever
APAAATAA
Sample output:
YES YES YES YES NO NO NO NO
#include <iostream> using namespace std; int main(){ int T; string tmp; cin>>T; while(T--){ bool no=false; cin>>tmp; //检测包含其他字符 for(int i=0;i<tmp.length();i++){ if(tmp[i]!='P'&&tmp[i]!='A'&&tmp[i]!='T'){ no=true;break; } } int P=tmp.find('P'); int T=tmp.find('T'); if(P==tmp.npos||T==tmp.npos){ no=true; } int front=P; int middle=T-P-1; int after=tmp.length()-T-1; if(no||middle==0) cout<<"NO"<<endl; else if(front*middle==after) cout<<"YES"<<endl; else cout<<"NO"<<endl; } system("pause"); return 0; }