[SWEA] 5186 이진수2

김은서·2021년 9월 30일
0

SWEA

목록 보기
42/47

Python code

T = int(input())
for tc in range(1, T+1):
    N = float(input())
    base = 1/2
    result = ''
    for i in range(12):
        if N - base >= 0:
            result += '1'
            N -= base
            base *= 1/2
        else:
            result += '0'
            base *= 1/2
        if N == 0:
            break
    if N:
        result = 'overflow'
    print('#{} {}'.format(tc, result))
profile
Gracelog

0개의 댓글