• Home
  • About
    • JOOS photo

      JOOS

      Joos's blog

    • Learn More
    • Email
    • Github
  • Posts
    • All Posts
    • All Tags
  • Projects

[백준] 2089번 : -2진수 with python3

03 Oct 2018

Reading time ~1 minute

문제: https://www.acmicpc.net/problem/2089

import sys
read = lambda : sys.stdin.readline().strip()

n = int(read())
base = 1
st = []
if n == 0:
	print(0)
else:
	while n :
		if n % 2 :
			st.append(1)
			n -= base
		else:
			st.append(0)
		base *= (-1)
		n //= 2

for i in reversed(range(len(st))):
	print(st[i], end="")



algorithm백준 Share Tweet +1