" correct answer " is the most delightful reply given by the automatic system. The question belongs to Pat's " answer correct " large dispatch--as long as the read-in string satisfies the following conditions, the system outputs " answer correct ", otherwise the output " answer error ".
The conditions for getting the answer right are:
1. The string must have only p, a, t these three characters, can not contain other characters;
2. Any string of arbitrary shapes, such as XPATX, can be " answered correctly ", where x is either an empty string or a string consisting of only the letter A;
3. If the APBTC is correct, then APBATCA is also correct, where a, B, c are either empty strings, or a string consisting of only the letter A.
Now ask you to write an automatic referee program for Pat to determine which strings are " correctly answered ".
input Format: Each test input consists of 1 test cases. The 1th line gives a natural number n (<10), which is the number of strings to be detected. Each string is followed by a single line, with a string length of no more than 100 and no spaces.
output format: The detection result of each string is one row, if the string can get " answer correct ", then output yes, otherwise output No.
Input Sample:
8PATPAATAAPATAAAAPAATAAAAxPATxPTWhateverAPAAATAA
Sample output:
Yesyesyesyesnononono
Did once the topic, incredibly does not have AH ah ah ah ah Ah!!
"Thinking" mathematical induction, p before the number of a *p and t between the number of a =t after the number of a
#include <iostream>#include<stdio.h>#include<string.h>#include<string>using namespacestd;Chars[106];intMain () {intN; scanf ("%d",&N); while(n--) {scanf ("%s", s); intlen=strlen (s); intPcnt=0, acnt=0, tcnt=0, flag=0; for(intI=0; i<len;i++) { if(s[i]=='A') acnt++; Else if(s[i]=='P') pcnt++; Else if(s[i]=='T') tcnt++; Else Gotoend; } if(pcnt==1&&tcnt==1&&acnt!=0) { Char* P1=STRCHR (s),'P');//STRCHR find the first p in S returns a pointerChar* P2=STRCHR (s),'T'); if((p1-s) * (p2-p1-1) ==strlen (p2)-1) Flag=1; } End:if(flag!=0) puts ("YES"); ElsePuts"NO"); }}
1003. I want to pass! _ Mathematical Induction