Love丶FFC's Blog
“答案正确”是自动判题系统给出的最令人欢喜的回复。本题属于 PAT 的“答案正确”大派送 —— 只要读入的字符串满足下列条件,系统就输出“答案正确”,否则输出“答案错误”。
得到“答案正确”的条件是:
P
、 A
、 T
这三种字符,不可以包含其它字符;xPATx
的字符串都可以获得“答案正确”,其中 x
或者是空字符串,或者是仅由字母 A
组成的字符串;aPbTc
是正确的,那么 aPbATca
也是正确的,其中 a
、 b
、 c
均或者是空字符串,或者是仅由字母 A
组成的字符串。现在就请你为 PAT 写一个自动裁判程序,判定哪些字符串是可以获得“答案正确”的。
每个测试输入包含 1 个测试用例。第 1 行给出一个正整数 n (<10),是需要检测的字符串个数。接下来每个字符串占一行,字符串长度不超过 100,且不包含空格。
每个字符串的检测结果占一行,如果该字符串可以获得“答案正确”,则输出 YES
,否则输出 NO
。
8
PAT
PAAT
AAPATAA
AAPAATAAAA
xPATx
PT
Whatever
APAAATAA
YES
YES
YES
YES
NO
NO
NO
NO
1.首先判断条件1
2.对条件2和条件3进行合并判断
3.条件3是递归定义,但是也有简单的规律可循
4.根据条件3的定义,发现条件3的规律如下:
xPATx
xPAATxx
xPAAATxxx
xPAAAATxxxx
xPAAAAATxxxxx
······
可以发现P与T之间A的个数与T右边x的个数一致,而P左边的x永远只有一个
因此x*(P与T之间A的个数)=T右边x的个数
在Python中,可以对字符串进行乘法运算,3*'A'="AAA"
NOS = int(input()) List = list() for i in range(NOS): Judge = True # 条件1标记 String = input() if 'P' in String and 'A' in String and 'T' in String: # 判断是否有P、A、T for j in range(len(String)): if String[j] != 'P' and String[j] != 'A' and String[j] != 'T': # 判断是否仅有P、A、T Judge = False break else: Judge = False if Judge == True: # 满足条件1 a = String[:String.find('P')] # 截取P左边的字符串 b = String[String.find('P') + 1:String.rfind('T')] # 截取P与T之间的字符串 c = String[String.rfind('T') + 1:] # 截取T右边的字符串 if (a == c and b == 'A') or (len(b) * a == c): # 满足条件2或条件3 print("YES") else: # 不满足条件2和条件3 print("NO") else: # 不满足条件1 print("NO")
cheap jordans online
Read reviews and was a little hesitant since I had already inputted my order. as well as but thank god, I had no issues. appreciate the received item in a timely matter, they are in new condition. situation so happy I made the purchase. Will be definitely be purchasing again.
cheap jordans online https://www.realjordansshoes.com/
authentic cheap jordans
Read reviews and was a little hesitant since I had already inputted my order. as well but thank god, I had no issues. simillar to the received item in a timely matter, they are in new condition. in any event so happy I made the purchase. Will be definitely be purchasing again.
authentic cheap jordans https://www.realcheapretrojordanshoes.com/
cheap louis vuitton outlet
Read reviews and was a little hesitant since I had already inputted my order. or maybe but thank god, I had no issues. such as the received item in a timely matter, they are in new condition. you ultimately choose so happy I made the purchase. Will be definitely be purchasing again.
cheap louis vuitton outlet https://www.louisvuittonsoutletonline.com/
cheap real jordans
Read reviews and was a little hesitant since I had already inputted my order. as well as but thank god, I had no issues. exactly like the received item in a timely matter, they are in new condition. regardless so happy I made the purchase. Will be definitely be purchasing again.
cheap real jordans https://www.realjordansretro.com/
Knitant
To this end, we stably transfected CHO cells with ESAM or JAM A and isolated cell clones expressing either ESAM or JAM A at similar levels Figure 6E generic cialis online europe For me, until I see a doctor and get an ultrasound to size the baby up it gives you the most accurate due date I pick one of the days I could have possible conceived, during ovulation, and use that
invoimi
top 10 viagra tablets Bear in mind that during this era, smoking was very common, and secondhand smoke was not seen as a violation of a non smoker s clean air