給定一個(gè)長度不超過 10^?4的、僅由英文字母構(gòu)成的字符串。請將字符重新調(diào)整順序已球,按 PATestPATest.... 這樣的順序輸出,并忽略其它字符辅愿。當(dāng)然智亮,六種字符的個(gè)數(shù)不一定是一樣多的,若某種字符已經(jīng)輸出完点待,則余下的字符仍按 PATest 的順序打印阔蛉,直到所有字符都被輸出。
輸入格式:
輸入在一行中給出一個(gè)長度不超過 10^4的癞埠、僅由英文字母構(gòu)成的非空字符串状原。
輸出格式:
在一行中按題目要求輸出排序后的字符串。題目保證輸出非空苗踪。
輸入樣例:
redlesPayBestPATTopTeePHPereatitAPPT
輸出樣例:
PATestPATestPTetPTePePee
代碼實(shí)現(xiàn):
standard_word = 'PATest'
word = [x for x in input() if x in standard_word]
counts = {'P':0,'A':0,'T':0,'e':0,'s':0,'t':0}
for item in word:
counts[item] += 1
counts = sorted(counts.items(), key=lambda x: x[1])
while True:
counts.sort(key=lambda x: x[1])
count = counts[0][1]
print(count * standard_word,end='')
counts = list(map(lambda x:(x[0],x[1]- count), counts))
for index,item in enumerate(counts):
if item[1] == 0:
standard_word = standard_word.replace(item[0],'')
counts.pop(index)
else:
break
if len(standard_word) == 0:
break