[ALGORITHM] BOJ 2745. 진법 변환
less than 1 minute read
ALGORITHM Übung - 백준
문제
코드
import sys
import string
if __name__ == "__main__":
# get input
n,b = sys.stdin.readline().split()
# make dictionary matching alphabet:number
d = dict(zip(string.ascii_uppercase, range(10, 36)))
b = int(b)
ans,j = 0,0
# add each digit_number * b ** j
for i in n[::-1]:
if i in d.keys():
ans += d[i] * b**j
else:
ans += int(i) * b**j
j += 1
print(ans)
# 다른 사람의 좋은 풀이
import sys
if __name__ == "__main__":
n,b = sys.stdin.readline().split()
print(int(n, int(b)))