22 lines
472 B
Python
22 lines
472 B
Python
|
import sys
|
||
|
|
||
|
def snafu2dec(s:str)->int:
|
||
|
D = {'0': 0, '1':1, '2':2, '-':-1, '=':-2 }
|
||
|
n = 0
|
||
|
for (i,c) in enumerate(reversed(s)):
|
||
|
n += 5**i * D[c]
|
||
|
return n
|
||
|
|
||
|
def dec2snafu(n:int) -> str:
|
||
|
d = "=-012"
|
||
|
l = []
|
||
|
while n>0:
|
||
|
r=(n+2)%5-2
|
||
|
l.append(d[r+2])
|
||
|
n = (n-r) // 5
|
||
|
return "".join(reversed(l))
|
||
|
|
||
|
|
||
|
if __name__ == "__main__":
|
||
|
print(dec2snafu(sum(snafu2dec(l) for l in sys.stdin.read().splitlines())))
|