Correct answer "is the most joy automatic reply sentence topic this question belongs to the system given the PAT." Correct answer "big delivery - just read the string following conditions are satisfied, the system will output" correct answer ", otherwise output "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
1 using System; 2 using System.Collections; 3 using System.Collections.Generic; 4 using System.Linq; 5 using System.Text; 6 using System.Text.RegularExpressions; 7 using System.Threading.Tasks; 8 9 namespace ConsoleApp5 10 { 11 class Program 12 { 13 static void Main(string[] args) 14 { 15 /*String contains only PAT, 1 th P, 1 th T, a plurality of A, and P before the constant T, PT directly to at least one A 16 * xPATx is correct, (x is the empty string or A) . 17 * Conditions 3 based on two conditions, if aPbTc is right, it is aPAbTca right 18 is * Suppose a (n), B (n ), C (n), n is the number of recursive containing a 19 * 2 based on the condition 20 is * the condition to give A (. 1) = C (. 1), B (. 1) =. 1 21 is * according to the conditions. 3 22 is * A (n-) = A (. 1), B (n-) = B (n--. 1) +. 1, C (n-) = C (n--. 1) + a (. 1) 23 is * solution 24 * a (n-) = a (. 1) 25 * B (n-) = B (. 1) + (n--. 1) =. 1 + n--. 1 = n- 26 is * C (n-) = C (. 1) + (n--. 1) * A (. 1) = n-* A (. 1) 27 * => A (n-) * B (n-) = C ( n-) 28 * / 29 30 int COUNT = 10 ; 31 is // input a numerical value, represents a number of cases to be tested 32 COUNT = Convert.ToInt32 (Console.ReadLine ()); 33 is // by storing the input of Example 34 is String [] = strin new new String [COUNT]; 35 // store or NO YES 36 String [] = strOut new new String [COUNT]; 37 [ // input and stored in strIn embodiment array 38 is for ( int I = 0 ; I <COUNT; I ++ ) 39 { 40 strin [I] = Console.ReadLine (); 41 is } 42 is 43 is // use case judge 44 is for ( int I = 0 ; I <COUNT; I ++ ) 45 { 46 is // pick-case "P", "T "number 47 int pNumber = Regex.Matches (strin [I], " P " ) .Count; 48 int tnumber = Regex.Matches (strin [I], " T " ) .Count; 49 // pick-case "P" "T" subscript 50 int indexP strin = [I].IndexOf(" P " ); 51 is int indexT = strin [I] .indexOf ( " T " ); 52 is // determines whether the use case PAT containing only three kinds of character 53 is for ( int J = 0 ; J <strin [I] .Length; J ++ ) 54 is { 55 IF (strin [I] [J]! = ' A ' && strin [I] [J]! = ' P ' && strin [I] [J]! = ' T ' ) 56 is { 57 is strOut [I] = "NO" ; 58 } 59 // selected character string containing only the PAT 60 the else 61 is { 62 is // screened P, T 1, a string of only the number 63 is IF (pNumber == 1 && tnumber == 1 ) 64 { 65 // P in front of the A 66 IF (indexP < indexT) 67 { 68 // Get lengtha, lengthb, lengthc, represents A (n-), B (n-), C (n-) 69 int lengtha, lengthb, lengthc; 70 String a, b, c; 71 a = strIn[i].Substring(0, indexP + 1); 72 lengtha = Regex.Matches(a, "A").Count; 73 74 b = strIn[i].Substring(indexP + 1, indexT - indexP - 1); 75 lengthb = Regex.Matches(b, "A").Count; 76 77 c = strIn[i].Substring(indexT + 1); 78 = Regex.Matches lengthc (C, " A " ) .Count; 79 // negative no direct PT A string 80 IF (lengthb == 0 ) 81 { 82 strOut [I] = " NO " ; 83 BREAK ; 84 ; 85 } 86 // satisfy the condition A (n-) * B (n-) = C (n-) 87 IF (lengtha lengthb == * lengthc) 88 { 89 strOut[i] = "YES"; 90 } 91 else 92 { 93 94 strOut[i] = "NO"; 95 } 96 97 } 98 else 99 { 100 101 strOut[i] = "NO"; 102 } 103 104 } 105 106 the else 107 { 108 strOut [I] = " NO " ; 109 } 110 } 111 } 112 113 114 } 115 // output answer 1 16 for ( int I = 0 ; I <COUNT; I ++ ) 117 { 118 Console.WriteLine(strOut[i]); 119 } 120 121 Console.ReadKey(); 122 } 123 } 124 }