Algorithm/Greedy
[백준] 1339번 단어수학
등촌동 꼬북이
2021. 1. 23. 18:14
오랜만에...
처음엔 리스트로 저장하면서 했다가 그럴 필요가 없어서..
ans = 0
value = 9
alphabet = [0] * 26
for i in range(int(input())):
bias = 0
for j in input()[::-1]:
alphabet[ord(j) - 65] += 10 ** bias
bias += 1
alphabet.sort(reverse=True)
for i in range(26):
if alphabet[i] == 0:
break
ans += value * alphabet[i]
value -= 1
print(ans)