๐ฃ 36์ง์
1. ๋ฌธ์ ๋งํฌ
2. ์ฝ๋
Python3
34148KB
72ms
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
# time : 50'
import sys
from collections import defaultdict
input = sys.stdin.readline
n = int(input())
str_list, num_list = [], []
num_cnt = defaultdict(int) # ์ซ์ ์ค์๋ ํ์ ์ฒดํน ๋์
๋๋ฆฌ
'''
๋ฌธ์์ด์ 36์ง์ ์ซ์ ๋ฆฌ์คํธ ํํ๋ก ๋ฆฌํด & ์ค์๋ ์ฒดํน
- ์ค์๋ : ์๋ฆฟ์ + {'Z' - ํ๊ฒ๊ฐ}
'''
def str_to_notation(num_cnt, target):
rst = []
for i in range(len(target)):
if (target[i].isdigit()):
t = int(target[i])
else:
t = (ord(target[i]) - ord('A')) + 10
num_cnt[t] += pow(36, len(target) - 1 - i) * (35 - t)
rst.append(t)
return rst
''' ์ซ์ ๋ฆฌ์คํธ๋ฅผ ์ต์ข
๋ฌธ์์ด๋ก ๋ฆฌํด '''
def num_list_to_str(num_list):
rst = 0 # 36์ง์ ์ซ์ ํํ๋ค์ ์ ์ฒด ํฉ
fin_str = ''
for i in range(n):
target = 0
for j in range(len(num_list[i]) - 1, -1, -1):
target = target + num_list[i][j] * \
pow(36, len(num_list[i]) - 1 - j)
rst += target
while rst: # 36์ง์์ ๋ฐ๋ฅธ ๋ฌธ์ ๋ณํ
t = rst % 36
if (t < 10):
fin_str = str(t) + fin_str
else:
fin_str = chr(t - 10 + ord('A')) + fin_str
rst //= 36
return fin_str if fin_str else '0' # 0์ผ ๋ ๊ณต๋ฐฑ ๋ฆฌํด exception [TC 87%]
for _ in range(n):
str_num = input().rstrip()
while (str_num[0] == '0' and len(str_num) > 1): # trim 0 ์ฒ๋ฆฌ exception [TC 87%]
str_num = str_num[1:]
notation = str_to_notation(num_cnt, str_num)
num_list.append(notation)
k = int(input())
# ์ค์๋์ ๋ฐ๋ฅธ ์ ๋ ฌ
list_cnt_notation = list(num_cnt.items())
list_cnt_notation.sort(key=lambda x: x[1], reverse=True)
for i in range(min(k, len(list_cnt_notation))):
t = list_cnt_notation[i][0]
for j in range(n):
for l in range(len(num_list[j])):
if num_list[j][l] == t:
num_list[j][l] = 35 # Z๋ก ๋ฐ๊ฟ์ฃผ๊ธฐ
print(num_list_to_str(num_list))
This post is licensed under CC BY 4.0 by the author.