practivceAlgorithm/swexpertacademy
[SWEA][Python] 5186 이진수2
findTheValue
2021. 9. 19. 20:40
정수를 이진수로 변환할때와 동일하게 재귀구조로 조건에 따라 1과 0을 더하며 파고드는 구조.
def binary(n,depth):
if depth>13:
return '2'
if not n:
return ''
if n >= 2**(-depth):
n -= 2**(-depth)
return '1' + binary(n,depth+1)
return '0' + binary(n,depth+1)
for test in range(1,int(input())+1):
N = float(input())
ans = binary(N,1)
if ans[-1]=='2':
ans = 'overflow'
print(f'#{test} {ans}')