t = int(input())
for tc in range(1,t+1):
n = float(input())
str = ''
while n != 1:
n *= 2
if n > 1:
n -= 1
str += '1'
elif n < 1:
str += '0'
else:
str += '1'
break
if len(str) < 13: print(f"#{tc} {''.join(str)}")
else: print(f"#{tc} overflow")
다음날 풀이
def solveBinary(n):
new_str = ''
cnt = 0
while n >0 and cnt < 13:
n *= 2
if n >= 1:
n -= 1
new_str += '1'
cnt += 1
else:
new_str += '0'
cnt += 1
if cnt >= 13:
return 'overflow'
else:
return new_str
t = int(input())
for tc in range(1,t+1):
n = float(input())
print(f'#{tc} {solveBinary(n)}')
'알고리즘 문제풀이' 카테고리의 다른 글
Swea D3_1240.단순 2진 암호코드 Python (0) | 2024.02.23 |
---|---|
Swea D3_11750.이진수1 Python 2진법 (0) | 2024.02.22 |
백준 1620. 나는야 포켓몬 마스터 이다솜 Python 실버4 (1) | 2024.02.21 |
baekjoon No Duplicates Bronze 1 (0) | 2024.02.21 |
Swea D2_11926. subset Python Tree (0) | 2024.02.21 |