2745번 : 진법 변환 - Python

Pobi·2023년 2월 5일
0

PS

목록 보기
41/107

문제

https://www.acmicpc.net/problem/2745

풀이

2진수 1000(8)을 10진수로 바꿀려면 1000 = (12^3)+(02^2)+(02^1)+(02^0) = 8을 이용한다.

코드

from sys import stdin, stdout

input = stdin.readline

system = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ'
n, b = input().split()
result = 0

for i in range(len(n)):
    result += system.index(n[i])*(int(b)**(len(n)-1-i))
print(result)

다른 풀이

python의 int함수를 이용해서 풀어본다. int(숫자, 숫자의 진법)이렇게 입력하면 10진수로 바꿔준다.

다른 코드

from sys import stdin

input = stdin.readline

n, b = input().split()

print(int(n,int(b)))
profile
꿈 많은 개발자

0개의 댓글