“答案正确”是自动判题系统给出的最令人欢喜的回复。本题属于PAT的“答案正确”大派送 —— 只要读入的字符串满足下列条件,系统就输出“答案正确”,否则输出“答案错误”。
得到“答案正确”的条件是:
1. 字符串中必须仅有P, A, T这三种字符,不可以包含其它字符;
2. 任意形如 xPATx 的字符串都可以获得“答案正确”,其中 x 或者是空字符串,或者是仅由字母 A 组成的字符串;
3. 如果 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 参考代码:
num = int(input()) for i in range(num): front=mid=last=k=0 tmpword = input() if tmpword=='PAT' or tmpword=='PAAT': print("YES") continue else: while tmpword[k]=='A' and k<len(tmpword)-1: front+=1 k+=1 if tmpword[k]!='P': print("NO") continue if k<len(tmpword)-1 : k+=1 while tmpword[k]=='A' and k<len(tmpword)-1: mid+=1 k+=1 if tmpword[k]!='T': print("NO") continue k+=1 while k<len(tmpword) and tmpword[k]=='A': last+=1 k+=1 if k<len(tmpword): print("NO") continue if front*mid==last and mid!=0: print("YES") else: print("NO")
貌似小点问题都出现在数组的越界上 第二个测试点是 'PA' 可以注意下
相关推荐
1003. 我要通过! PAT C++,可用
POSIX接口标准, PSE51, PSE52, PSE54, IEEEStd1003.13-2003IEEEStandardforInformationTechnology-StandardizedApplicationEnvironmentProfile(AEP_-POSIXRealtim
IEEE Std 1003.1, 2004 Edition.rar,包含CHM,HTML
International Standard ISO/IEC 9945-1: 1996 (E) IEEE Std 1003.1, 1996 Edition (Incorporating ANSI/IEEE Stds 1003.1-1990, 1003.1b-1993,
此文档是POSIX标准最新文档HTML版,UNIX/LINUX系统编程和实现必备手册。 The Open Group Base Specifications Issue 7, 2018 edition IEEE Std 1003.1-2017 (Revision of IEEE Std 1003.1-2008)
Scheduling under Posix 1003.1b Scheduling under Posix 1003.1b
Everything-1.4.1.1003.x64.zip win版本全盘搜索工具
POSIX官方文档:Base Definitions, Issue 7 (XBD7) System Interfaces, Issue 7 (XSH7) Shell and Utilities, Issue 7 (XCU7) Rationale, Issue 7 (XRAT7)
IEEE 1003.1 2008加上TC1和TC2
speedupper2.3.1003.18speedupper2.3.1003.18speedupper2.3.1003.18speedupper2.3.1003.18
POSIX 1003.1-2004
POSIX(IEEE Std 1003.1-2008),POSIX的官方资料,可以参考学习,HTML格式的。
POSIX.1-2017同时是IEEE Std 1003.1™-2017和The Open Group Standard Base Specification第7版。 POSIX.1-2017定义了标准的操作系统接口和环境,包括命令解释器(或“ shell”)和通用实用程序,以在源代码级别支持...
根据《IEEE Std 1003.1-2008》生成用于VIM的TAGS
Kyligence官方驱动包Kyligence.ODBC.3.1.9.1003.Linux.x64.tar.gz
AUTOSAR
SafeInstaller_1.0.0.1003.exe
反编译工具 支持 VS 2015
带目录,协议原版
NANDLite_v1.0.1003.43.zip