1043 输出PATest (20 分)
给定一个长度不超过 104 的、仅由英文字母构成的字符串。请将字符重新调整顺序,按 PATestPATest....
这样的顺序输出,并忽略其它字符。当然,六种字符的个数不一定是一样多的,若某种字符已经输出完,则余下的字符仍按 PATest 的顺序打印,直到所有字符都被输出。
输入格式:
输入在一行中给出一个长度不超过 104 的、仅由英文字母构成的非空字符串。
输出格式:
在一行中按题目要求输出排序后的字符串。题目保证输出非空。
输入样例:
redlesPayBestPATTopTeePHPereatitAPPT
输出样例:
PATestPATestPTetPTePePee
思路是BTboay 大佬的
制作一个字典,需要找的字母为key,对应的数量为value
然后循环输出,每输出一次就给value减1
x=input()
ls=[]
ls_stand=['P','A','T','e','s','t']
for i in x:
ls.append(i)
for i in ls:
if i in ls_stand:
pass
else:
ls.remove(i)
dic={'P':0,'A':0,'T':0,'e':0,'s':0,'t':0}
for i in ls:
if i in dic:
dic[i]+=1
P=1
A=1
T=1
e=1
s=1
t=1
while dic['P']>0 or dic['A']>0 or dic['T']>0 or dic['e']>0 or dic['s']>0 or dic['t']>0:
if dic['P']==0:
P=0
if dic['A']==0:
A=0
if dic['T']==0:
T=0
if dic['e']==0:
e=0
if dic['s']==0:
s=0
if dic['t']==0:
t=0
print('{}{}{}{}{}{}'.format('P'*P,'A'*A,'T'*T,'e'*e,'s'*s,'t'*t),end='')
dic['P']-=1
dic['A']-=1
dic['T']-=1
dic['e']-=1
dic['s']-=1
dic['t']-=1