Post

백준 1339 (단어 수학)

백준 1339 (단어 수학)

문제 링크

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

문제 접근

소스 코드

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
import sys

n=int(input())
word_count=dict()
answer=0

for _ in range(n) :
    word = sys.stdin.readline().strip()
    word = word[::-1]
    for i in range(len(word)) :
        if word[i] not in word_count :
            word_count[word[i]]=0
        word_count[word[i]]+=10**i
        
word_count = sorted(word_count.items(), key=lambda item:item[1], reverse=True)
num=9

for word in word_count:
    answer+=word[1]*num
    num-=1
print(answer)

마무리하며

This post is licensed under CC BY 4.0 by the author.