Pat B true title 1003. I'm going through! (20) (Problem solving)

Source: Internet
Author: User

" correct answer "is the most delightful reply given by the automated 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 Output Sample: Yesyesyesyesnononono

Code

`/********* Compilation Environment **vc++ 6.0 (32-bit) *************/#include<stdio.h>#include<string.h>#include<malloc.h>#defineM 101intMain () {intn,i,j; intcp=0, ct=0, ca=0, flag=0, ce=0; Char**s; Char*p1,*P2; scanf ("%d",&N); S=(Char**)malloc(nsizeof(Char*));//defining the first column     for(i=0; i<n;i++) {S[i]=(Char*)malloc(m*sizeof(Char));//Defining Rowsscanf"%s", S[i]); Strcat (S[i]," /"); }     for(i=0; i<n;i++) {CP=0; CT=0; CA=0; Ce=0;  for(j=0; s[i][j]!=' /'; j + +)        {            if(s[i][j]=='P') CP++; Else if(s[i][j]=='T') CT++; Else if(s[i][j]=='A') CA++; ElseCE=1; }        if(cp==1&&ct==1&&ca!=0&&ce==0) {P1=STRCHR (S[i],'P'); P2=STRCHR (S[i],'T'); if((P1-s[i]) * (p2-p1-1) ==strlen (p2)-1) Flag=1; }        ElseFlag=0; if(flag==1) printf ("yes\n"); Elseprintf ("no\n"); }    return 0;}`

Pat B true title 1003. I'm going through! (20) (Problem solving)

Related Keywords:

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

• Sales Support

1 on 1 presale consultation

• After-Sales Support

24/7 Technical Support 6 Free Tickets per Quarter Faster Response

• Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.