用python来解PAT乙级1043输出PATest-20-满分

这题不难,应该大部分人都能做出来,我这里是因为觉得当某一种字符输出完之后其他的处理的麻烦,所以先对每个字符计数,然后顺序判断,不为0就输出,这样其他的顺序也仍旧不会改变,虽然代码没有很短,但是思路很容易理解和掌握

代码:

ss = input()
P = A = T = e = s = t = 0
for i in ss:
    if i == 'P':
        P += 1
    elif i == 'A':
        A += 1
    elif i == 'T':
        T += 1
    elif i == 'e':
        e += 1
    elif i == 's':
        s += 1
    elif i == 't':
        t += 1

while P or A or T or e or s or t:
    if P > 0:
        print('P', end='')
        P -= 1
    if A > 0:
        print('A', end='')
        A -= 1
    if T > 0:
        print('T', end='')
        T -= 1
    if e > 0:
        print('e', end='')
        e -= 1
    if s > 0:
        print('s', end='')
        s -= 1
    if t > 0:
        print('t', end='')
        t -= 1

提交结果:

用python来解PAT乙级1043输出PATest-20-满分