[백준 1431][Python] 시리얼 번호

봉글렛·2023년 5월 15일

백준

목록 보기
55/55

문제 링크 https://www.acmicpc.net/problem/1431

딕셔너리로 풀어봄.

풀이

import re

n = int(input())
d = dict()
for _ in range(n):
    inp = input()
    if len(inp) in d:
        d[len(inp)][inp] = sum([int(i) for i in re.sub(f'[^1-9]', '', inp)])
    else:
        d[len(inp)] = {inp: sum([int(i) for i in re.sub(f'[^1-9]', '', inp)])}

for i in sorted(d.keys()):
    for j in sorted(sorted(d[i].items()), key=lambda x: x[1]):
        print(j[0])
profile
어쩌다 개발자 (할 수 있을 때까지!!!!)

0개의 댓글