[Greedy] 1339번 - 단어 수학(57일차)

bob.sort·2021년 9월 1일
0
post-thumbnail
post-custom-banner
import sys
input = sys.stdin.readline

N = int(input())
word_list = []

alphabet_dict = {}
alphabet_value = []

answer = 0

for _ in range(N):
    word = input().rstrip()
    word_list.append(word)

for word in word_list:
  for i in range(len(word)):
    num = 10 ** (len(word) - i - 1)
    try:
      alphabet_dict[word[i]] += num
    except:
      alphabet_dict[word[i]] = num

for value in alphabet_dict.values():
  alphabet_value.append(value)

sorted_list = sorted(alphabet_value, reverse=True)

for i in range(len(sorted_list)):
  answer += sorted_list[i] * (9 - i)

print(answer)
profile
Interest in Computer Graphics and Computer Vision
post-custom-banner

0개의 댓글