题目思路:
1.字符串处理,去掉PATest以外字符
2.建立集合,计算所有PATest字符数量
3.按顺序输出字符
import re
if __name__ == '__main__':
sentence = input()
sentence=''.join(re.split(r'[^PATest]', sentence))
set_sentence={'P':0,"A":0,"T":0,'e':0,'s':0,'t':0}
for x in sentence:
set_sentence[x]+=1
Pat='PATest'
while set_sentence['P'] !=0 or set_sentence['A'] !=0 or set_sentence['T'] !=0 or set_sentence['e'] !=0 or set_sentence['s'] !=0 or set_sentence['t'] !=0:
#这里通过字符串Pat 来控制顺序
for c in Pat:
if set_sentence[c] != 0:
set_sentence[c]-=1
print(c,end='')