πΉ 36μ§μ
1. λ¬Έμ λ§ν¬
2. μ½λ
Python3
31120KB
48ms
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
N = int(input())
numbers = []
reverse_numbers = []
for _ in range(N):
numbers.append(input().replace(' ', ''))
K = int(input())
def change_36_to_demical(x):
if 48 <= ord(x) <= 57:
return int(x)
else:
return ord(x) - 55
def change_demical_to_36(num):
if 0 <= num <= 9:
return str(num)
else:
return chr(num + 55)
# μ€μλ κ³μ°(μ€μλ, μμΉ)
importance = [[0, i] for i in range(36)]
for n in numbers:
number = list(n)
number.reverse()
reverse_numbers.append(number)
for i in range(len(number)):
alpha = number[i]
# μ΄λ―Έ Zλ λ³κ²½ν νμ μμ
if alpha == 'Z':
continue
dnum = change_36_to_demical(alpha)
# μλ¦Ώμμ μ«μμ ν¬κΈ° λͺ¨λλ‘ μ€μλ κ³μ°(λ μμ μ«μκ° λ³κ²½ μ€μλ λλ€)
importance[dnum][0] += (35-dnum) * (36 ** i)
importance.sort(key=lambda x: -x[0])
importance = importance[:K]
change_num = []
for im in importance:
change_num.append(im[1])
# 10μ§μλ‘ κ³μ°ν μ«μ
demical_num = 0
for r_num in reverse_numbers:
for i in range(len(r_num)):
dnum = change_36_to_demical(r_num[i])
# Zλ‘ λ³ννλ μ«μ
if dnum in change_num:
dnum = 35
demical_num += dnum * (36 ** i)
answer = ''
while demical_num:
n = change_demical_to_36(demical_num % 36)
demical_num //= 36
answer = n + answer
# '002'μ κ°μ λ΅μΌλ μμ '00' μ κ±°
answer = list(answer)
for i in range(len(answer)):
if answer[i] != 0:
answer = answer[i:]
break
if answer:
print(''.join(answer))
else:
print('0')
3. ν΄μ€
κ° 36μ§μ μ«μμ μ€μλλ₯Ό κ³μ°ν΄μΌνλ€. μ€μλλ $(35-μ«μ)*36^{μλ¦Ώμ}$λ‘ κ³μ°νλ κ²μ΄ μ ννλ€.
35-μ«μ
λ₯Ό ν΄μ€ κ²μ μ«μκ° μμμλ‘ μ€μλκ° λμμ§κΈ° λλ¬Έμ κ°μ₯ ν° μ«μ Z(=35)μμ λΉΌμ£Όλ κ²μ΄λ€.
μ€μλλ‘ μ ν΄μ§ μ«μλ λͺ¨λ 35λ‘ λ°κΏμ€ ν 10μ§μ κ³μ°μ νλ€.
10μ§μλ‘ κ³μ°λ μ«μλ₯Ό 36μΌλ‘ λλ κ°λ©° 36μ§μ μ«μλ‘ λ°κΏμ€λ€.
μ΄λ, μ΅μ’ μ«μκ° β000β νΉμ β00203β λ± 0μΌλ‘ μμνλ κ²½μ° β0β νΉμ β203βμΌλ‘ λ°κΏμ€λ€.
This post is licensed under CC BY 4.0 by the author.