Question
문제링크
Silver 3
Logic
기본 구조 : dictionary
1. 입력된 단어내에 '숫자 기호'를 탐색하고 그 숫자를 더한다.
2. 단어의 길이를 key로 하여 딕셔러니 안에 [값,단어]로 저장한다.
3. 입력이 완료되면 길이별로 정렬한 뒤 출력한다.
Code
from sys import stdin
data = {}
for _ in range(int(stdin.readline().rstrip())):
ss = stdin.readline().rstrip()
l = len(ss)
cnt = 0
for i in ss:
if i.isdigit() : cnt += int(i)
if l not in data.keys(): data[l] = [[cnt,ss]]
else : data[l].append([cnt,ss])
for k in sorted(data.keys()):
for dd in sorted(data[k]): print(dd[1])