Problem:


図書整理

 数の表わし方には色々な種類があり、私たちが普段使っている 10 進数は一つの代表的なものでしかありません。コンピュータ関連の知識がある人には、2 進数、16 進数あたりはとても身近なものです。

N さんは司書資格を活かして司書の仕事に就きました。最初の仕事は図書整理です。この図書館では、一冊ごとに一貫して番号が与えられており、それに従って本を整理しています。

この図書館では本の番号をマイナス十進数で表すことになっています。

 マイナス十進数は、anan&minus;1an&minus;2...a2a1a0 (各ai は 0~9 の数字) と表記する方法であり、この数は次の数を表します。

an&times;(&minus;10)n + an&minus;1&times;(&minus;10)n&minus;1 + ... + a2&times;(&minus;10)2 + a1&times;(&minus;10)1 + a0&times;(&minus;10)0

 たとえば、マイナス十進数の 2156 は、以下のとおり十進数の-1944 に対応しています。

2&times;(-10)3 + 1&times;(-10)2 + 5&times;(-10)1 + 6&times;(-10)0 = 

2&times;(-1000) + 1&times;(100) + 5&times;(-10) + 6&times;(1) = 

-2000 + 100 - 50 + 6 = -1944

 十進数の番号をマイナス十進数に直すのは大変なので、N さんは大変不自由な思いをしています。

 本の番号を入力とし、 この番号のマイナス十進数表記を出力するプログラムを作成してください。

Input

複数のデータセットの並びが入力として与えられます。入力の終わりはゼロひとつの行で示されます。各データセットとして、本の番号を表す整数 A (-231 ≤ A < 231) が１行に与えられます。

データセットの数は 1200 を超えません。

Output

入力データセットごとに、番号のマイナス十進数表記を１行に出力します。

Sample Input

9
10
-10
-1944
-305432133
0

Output for the Sample Input

9
190
10
2156
1715573947



Sample input:
9
10
-10
-1944
-305432133
0


Sample output:
9
190
10
2156
1715573947

Submission status: Wrong Answer

Solution code:
while True:
    X = input()
    if X == '0': break
    r = ''
    minus = False
    if X[0] == '-':
        minus = True
        X = X[1:]

    kuri = 0
    for a in [int(a) for a in X[::-1]]:
        if minus and a > 0:
            # r.insert(0, kuri + 10 - a)
            r = str(kuri + 10 - a) + r
            kuri = 1
        else:
            # r.insert(0, kuri + a)
            r = str( kuri + a) + r
            kuri = 0
        # r.insert(0, (lambda x: x+kuri)(10 - a if minus else a))

        minus = not minus

    # r.insert(0,kuri)
    r = str(kuri) + r
    print(int(r))

Submission status: Wrong Answer

Solution code:

while True:
    X = input()
    if X == '0': break
    r = ''
    minus = False
    if X[0] == '-':
        minus = True
        X = X[1:]

    kuri = 0
    for a in [int(a) for a in X[::-1]]:
        if minus and a > 0:
            # r.insert(0, kuri + 10 - a)
            r = str(kuri + 10 - a) + r
            kuri = 1
        else:
            # r.insert(0, kuri + a)
            r = str((kuri + a) % 10) + r
            kuri = (kuri + a) // 10 
        # r.insert(0, (lambda x: x+kuri)(10 - a if minus else a))

        minus = not minus

    # r.insert(0,kuri)
    r = str(kuri) + r
    print(int(r))

Submission status: Wrong Answer

Solution code:
while True:
    X = input()
    if X == '0': break
    r = ''
    minus = False
    if X[0] == '-':
        minus = True
        X = X[1:]

    kuri = 0
    for a in [int(a) for a in X[::-1]]:
        if minus and a > 0:
            # r.insert(0, kuri + 10 - a)
            r = str((kuri + 10 - a) % 10) + r
            kuri = 0 if kuri - a == 0 else 1
        else:
            # r.insert(0, kuri + a)
            r = str((kuri + a) % 10) + r
            kuri = (kuri + a) // 10 
        # r.insert(0, (lambda x: x+kuri)(10 - a if minus else a))

        minus = not minus

    # r.insert(0,kuri)
    r = str(kuri) + r
    print(int(r))

Submission status: Wrong Answer

Solution code:
import math

def func(n):
    #check length
    q=int(math.log10(abs(n)))
    if n*(-1)**(q%2)>0:
        p=(-10)**(q)*(n/(-10)**(q))
    else:
        p=(-10)**(q+1)
    r=n-p
    return (abs(p), r)
    
    
while(1):
    n=int(raw_input())
    if n==0:
        break
    ans=0
    while(n!=0):
        [ap,n]=func(n)
        ans+=ap
    print ans

Submission status: Wrong Answer

Solution code:
import math

def func(n):
    #check length
    q=int( len( str( abs(n)) )) -1
    if n*(-1)**(q%2)>0:
        p=(-10)**(q)*(n/(-10)**(q))
    else:
        p=(-10)**(q+1)
    r=n-p
    return (abs(p), r)
    
    
while(1):
    n=int(raw_input())
    if n==0:
        break
    ans=0
    while(n!=0):
        [ap,n]=func(n)
        ans+=ap
    print ans

Submission status: Wrong Answer

Solution code:
import math

def func(n):
    #check length
    q=int(math.log10(abs(n)))
    if n*(-1)**(q%2)>0:
        p=(-10)**(q)*(n/(-10)**(q))
    else:
        p=(-10)**(q+1)
    r=n-p
    return (abs(p), r)
    
def check_safe_oc(ans, ap):
    q=int(math.log10(ap))
    anq= ((ans%10**(q+1))/10**q)*10**q
    return [int(math.log10(ap+anq))==q , q]


while(1):
    n=int(raw_input())
    if n==0:
        break
    ans=0
    while(n!=0):
        [ap,n]=func(n)
        coc,q=check_safe_oc(ans,ap)
        if coc:
            ans+=ap
        else:
            ans  = (ans/10**(q+1))*10**(q+1)+ans%10**q
            ans += 19*10**(q+1)
    print ans

Submission status: Wrong Answer

Solution code:
while True:
    nums = raw_input().strip()
    if nums == '0':
        break

    nums = list(nums)
    nums.reverse()

    minus = False
    if nums[-1] == '-':
        minus = True
        nums.pop()
        nums = [0] + nums

    nums = map(int, nums)

    for i in range(len(nums)):
        if i % 2 != 0:
            nums[i] = -nums[i]

    for i in range(len(nums)):
        if nums[i] < 0:
            nums[i] += 10
            if i == len(nums) - 1:
                nums = nums + [0]
            nums[i + 1] += 1
        elif nums[i] == 10:
            nums[i] = 0
            if i == len(nums) - 1:
                nums = nums + [0]
            nums[i + 1] += 1

    if minus:
        del nums[0]

    print ''.join(map(str, reversed(nums)))

Submission status: Wrong Answer

Solution code:
while 1:
	n = raw_input()[::-1]
	if n == "0": break
	ans = ""
	m = 1 if n[-1] == "-" else 0
	for i in range(0, len(n) - m, 2):
		if int(n[i]) > 0:
			if i < len(n) - 1 - m:
				ans += str(10 - int(n[i])) + str(int(n[i + 1]) + 1)
			else:
				ans += str(10 - int(n[i])) + "1"
		else:
			ans += "0" + n[i + 1]
	ans = int("2"+"0"*len(n)) - int(ans[::-1]) if m == 0 else int(ans[::-1])
	print ans

Submission status: Wrong Answer

Solution code:
while 1:
	n = raw_input()[::-1]
	if n == "0": break
	ans = ""
	m = 1 if n[-1] == "-" else 0
	for i in range(0, len(n) - m, 2):
		if int(n[i]) > 0:
			if i < len(n) - 1 - m:
				ans += str(10 - int(n[i])) + str(int(n[i + 1]) + 1)
			else:
				ans += str(10 - int(n[i])) + "1"
		else:
			ans += "0" + n[i + 1]
	if len(n) == 1 or (m == 0 and n[0] == "0"):
		ans = int("2"+"0"*len(n)) - int(ans[::-1]) 
	else:
		ans = int(ans[::-1])
	print ans

Submission status: Wrong Answer

Solution code:
while 1:
	n = raw_input()[::-1]
	if n == "0": break
	ans = ""
	if n[-1] == "-":
		for i in range(0, len(n) - 1, 2):
			if int(n[i]) > 0:
				if i < len(n) - 2:
					ans += str(10 - int(n[i])) + str(int(n[i + 1]) + 1)
				else:
					ans += str(10 - int(n[i])) + "1"
			else:
				ans += "0" + n[i + 1]
	else:
		m = 1 if len(n)%2 == 1 else 2
		for i in range(0, len(n) - m, 2):
			if int(n[i]) > 0:
				ans += str(10 - int(n[i])) + str(int(n[i + 1]) + 1)
			else:
				ans += "0" + n[i + 1]
		if m == 1:
			ans += n[-1]
		else:
			ans += n[-2] + str(20-int(n[-1]))[::-1]
	print ans[::-1]

Submission status: Accepted

Solution code:
while True:
    X = input()
    if X == '0': break
    r = ''
    minus = False
    if X[0] == '-':
        minus = True
        X = X[1:]

    kuri = 0
    #for a in [int(a) for a in X[::-1]]:
    idx = len(X)-1
    while idx >= 0:
        a = int(X[idx])

        if minus:
            # r.insert(0, kuri + 10 - a)
            r = str((10 - a - kuri) % 10) + r
            kuri = 0 if kuri + a == 0 else 1
        else:
            # r.insert(0, kuri + a)
            r = str((kuri + a) % 10) + r
            kuri = (kuri + a) // 10 
        # r.insert(0, (lambda x: x+kuri)(10 - a if minus else a))

        minus = not minus
        if idx == 0 and kuri > 0:
            X = '0' + X
        else:
            idx -= 1

    # r.insert(0,kuri)
    r = str(kuri) + r
    print(int(r))

Submission status: Accepted

Solution code:
while 1:
    n=int(input())
    if n==0:break
    a=''
    while n:
        b=n%10
        if b<0:b+=10
        a+=str(b)
        n=(n-b)//(-10)
    print(a[::-1])

Submission status: Accepted

Solution code:
import math

def func(n):
    #check length
    q=int(math.log10(abs(n)))
    if n*(-1)**(q%2)>0:
        p=(-10)**(q)*(n/(-10)**(q))
    else:
        p=(-10)**(q+1)
    r=n-p
    return (abs(p), r)
    
def check_safe_oc(ans, ap):
    q=int(math.log10(ap))
    if ans==0 or q>int(math.log10(ans)): return [True , q]
    anq= ((ans%10**(q+1))/10**q)*10**q
    return [int(math.log10(ap+anq))==q , q]


def addans(ans,ap):
    coc,q=check_safe_oc(ans,ap)
    if coc:
        ans+=ap
    else:
        ans  = (ans/10**(q+1))*10**(q+1)+ans%10**q
        ans +=  9*10**(q+1)
        ans = addans(ans,10**(q+2))
    return ans

#for n in range(910,100000):
#    norg=n
#    ans=0
#    while(n!=0):
#        [ap,n]=func(n)
#        ans=addans(ans,ap)
#    if norg!=checkok(ans):
#        print norg,ans,checkok(ans)
#        break
#def checkok(ans):
#    ret=0
#    sa=str(ans)
#    lena=len(sa)
#    for i in range(lena):
#        ret+=int(sa[-i-1])*(-10)**(i)
#    return ret

while(1):
    n=int(raw_input())
    if n==0:
        break
    ans=0
    while(n!=0):
        [ap,n]=func(n)    
        ans=addans(ans,ap)
    print ans

Submission status: Accepted

Solution code:
while True:
    n=int(input())
    if n==0:break
    s=str(n)[::-1]
    digi=[int(s[i])*((-1)**i) for i in range(len(s))]if n>=0 else [-int(s[i])*((-1)**i)for i in range(len(s)-1)]
    for i in range(2):digi.append(0) 
    l=len(digi)
    negdec=0
    for k in range(l):
        a=digi[k]
        if a<0:
            negdec+=(10+a)*(10**k)
            digi[k+1]+=1
        elif a>=10:
            negdec+=(a-10)*(10**k)
            digi[k+1]-=1
        else:
            negdec+=a*(10**k)
    print(negdec)

Submission status: Accepted

Solution code:
# AOJ 0233: Book Arrangement
# Python3 2018.6.26 bal4u

while True:
    a = int(input())
    if a == 0:break
    ans = ''
    while a != 0:
        b = a % 10
        if b < 0: b += 10
        ans += str(b)
        a -= b
        a //= -10
    print(ans[::-1])

Submission status: Accepted

Solution code:
while True:
    nums = raw_input().strip()
    if nums == '0':
        break

    nums = list(nums)
    nums.reverse()

    minus = False
    if nums[-1] == '-':
        minus = True
        nums.pop()
        nums = [0] + nums

    nums = map(int, nums)

    for i in range(len(nums)):
        if i % 2 != 0:
            nums[i] = -nums[i]

    for i in range(len(nums) + 1):
        try:
            if nums[i] < 0:
                nums[i] += 10
                if i == len(nums) - 1:
                    nums = nums + [0]
                nums[i + 1] += 1
            elif nums[i] == 10:
                nums[i] = 0
                if i == len(nums) - 1:
                    nums = nums + [0]
                nums[i + 1] -= 1
        except IndexError:
            pass

    if minus:
        del nums[0]

    print ''.join(map(str, reversed(nums)))

Submission status: Accepted

Solution code:
while True:
    nums = raw_input().strip()
    if nums == '0':
        break

    nums = list(nums)
    nums.reverse()

    plus = True
    try:
        nums.remove('-')
        plus = False
    except:
        pass

    nums = map(int, nums)

    for i in range(len(nums)):
        if plus:
            if i % 2 != 0:
                nums[i] = -nums[i]
        else:
            if i % 2 == 0:
                nums[i] = -nums[i]

    for i in range(len(nums) + 1):
        try:
            if nums[i] < 0:
                nums[i] += 10
                if i == len(nums) - 1:
                    nums = nums + [0]
                nums[i + 1] += 1
            elif nums[i] == 10:
                nums[i] = 0
                if i == len(nums) - 1:
                    nums = nums + [0]
                nums[i + 1] -= 1
        except IndexError:
            pass

    print ''.join(map(str, reversed(nums)))

Submission status: Accepted

Solution code:
while 1:
    N = int(input())
    if N == 0:
        break
    R = []
    c = 0
    while N:
        if c:
            if N % 10 > 0:
                R.append(10 - (N % 10))
                N += 10
            else:
                R.append(0)
        else:
            R.append(N % 10)
        c ^= 1
        N //= 10
    R.reverse()
    print(*R, sep='')

Submission status: Accepted

Solution code:
while True:
    n = int(input())
    if n == 0:
        break
    d = 1
    ans = 0
    b = 1
    while n != 0:
        x = n%(10*b)*b
        ans = ans+x*d
        n -= x*b
        n //= 10
        b *= -1
        d *= 10
    print(ans)

Submission status: Runtime Error

Solution code:
while True:
    A = input()
    if A == '0':
        break
    print(sum(int(a)*pow(-10, i) for i, a in enumerate(A[::-1])))