정렬하는 문제이다.
첫 번째 정렬기준은 길이 순으로 정렬하는 것이다.
두 번째 정렬기준은 모든 자릿수의 합과 비교하여 작은 합을 기준으로 정렬한다.
세 번째 정렬기준으로는 사전순으로 정렬하는 것이다.
파이썬에서 lamda를 사용해서 3가지 기준으로 정렬을 할 수 있다.
for test_case in range(1):
n = int(sys.stdin.readline())
arr = []
for _ in range(n):
arr.append(sys.stdin.readline().rstrip())
def get_total(string):
total = 0
for s in string:
if s.isdigit():
total += int(s)
return total
arr.sort(key = lambda x:(len(x), get_total(x), x))
for ans in arr:
print(ans)