1003 我要通过 (20 分)

答案正确”是自动判题系统给出的最令人欢喜的回复。本题属于 PAT 的“答案正确”大派送 —— 只要读入的字符串满足下列条件,系统就输出“答案正确”,否则输出“答案错误”。

得到“答案正确”的条件是:

  1. 字符串中必须仅有 P、 A、 T这三种字符,不可以包含其它字符;
  2. 任意形如 xPATx 的字符串都可以获得“答案正确”,其中 x 或者是空字符串,或者是仅由字母 A 组成的字符串;
  3. 如果 aPbTc 是正确的,那么 aPbATca 也是正确的,其中 a、 b、 c 均或者是空字符串,或者是仅由字母 A 组成的字符串。

现在就请你为 PAT 写一个自动裁判程序,判定哪些字符串是可以获得“答案正确”的。

输入格式:

每个测试输入包含 1 个测试用例。第 1 行给出一个正整数 n (≤10),是需要检测的字符串个数。接下来每个字符串占一行,字符串长度不超过 100,且不包含空格。

输出格式:

每个字符串的检测结果占一行,如果该字符串可以获得“答案正确”,则输出 YES,否则输出 NO

输入样例:

10
PAT
PAAT
AAPATAA
AAPAATAAAA
xPATx
PT
Whatever
APAAATAA
APT
APATTAA

结尾无空行

输出样例:

YES
YES
YES
YES
NO
NO
NO
NO
NO
NO

结尾无空行

#!/usr/bin python
# -*- encoding: utf-8 -*-
'''
@Author  :   Celeste Young
@File    :   1003我要通过.py    
@Time    :   2021/11/10 21:08  
@E-mail  :   iamwxyoung@qq.com
@Tips    :   https://pintia.cn/problem-sets/994805260223102976/problems/994805323154440192
'''


def isA(s):
    for i in range(len(s)):
        if s[i] != "A":
            return False
    return True


def isCorrect(ls):
    if 'P' not in ls or 'A' not in ls or 'T' not in ls:
        return 'NO'
    if 'P' in ls and 'T' in ls:
        if ls.count('P') == 1 and ls.count('T') == 1:
            if ls.index('P') < ls.index('T'):
                if ls.split('P')[0] == '':
                    if ls.split('P')[1].split('T')[1] == '' and len(ls.split('P')[1].split('T')[0]) >= 1:
                        if isA(ls.split('P')[1].split('T')[0]):
                            return "YES"
                        return "NO"
                    return "NO"
                else:
                    if isA(ls.split('P')[0]) and ls.split('P')[1].split('T')[0] != '':
                        if isA(ls.split('P')[1].split('T')[1]) and len(ls.split('P')[1].split('T')[1]) \
                                == len(ls.split('P')[0]) * len(ls.split('P')[1].split('T')[0]):
                            return "YES"
                        return "NO"
                    return "NO"
                    # if len(ss[0]) * len(ss[1]) == len(ss[2]):
                    #     return 'YES'
            return 'NO'
        return "NO"
    return "NO"


if __name__ == '__main__':

    x = int(input())
    a = [None for i in range(x)]
    for i in range(x):
        a[i] = input()
    for i in a:
        print(isCorrect(i))

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值