Algorithm PS/BOJ
[BOJ] 1212 / 8진수 2진수 / Python 파이썬
migrationArc
2021. 6. 1. 11:00
[BOJ] 1212 / 8진수 2진수 / Python 파이썬
https://www.acmicpc.net/problem/1212
1212번: 8진수 2진수
첫째 줄에 8진수가 주어진다. 주어지는 수의 길이는 333,334을 넘지 않는다.
www.acmicpc.net
풀이
8진수를 2진수로 변환하는 문제이다.
8진수의 한자리를 2진수의 3자리로 변환하면 된다.
eights = input()
res = ""
for i in range(len(eights)):
n = int(eights[i])
tmp = ""
while n != 0:
tmp += str(n % 2)
n //= 2
if i != 0:
while len(tmp) < 3:
tmp = tmp+"0"
res += tmp[::-1]
if not res:
print(0)
else:
print(res)
\