2022年3月31日 星期四

UVa10035 Primary Arithmetic (Python)

 

flag = True
a, b, c = 0, 0, 0
operations = 0
run = True
def count():
    global operations, a, b, c
    if a==0 and b==0 and c==0:
        return
    if (a%10)+(b%10)+c > 9:
        operations = operations + 1
        c = int(((a%10)+(b%10)+c)/10)
        a = int(a/10)
        b = int(b/10)
        count()
    else:
        c = 0
        a = int(a/10)
        b = int(b/10)
        count()
while run == True:
    for s in input().split():
        if flag == True:
            flag = not flag
            operations = 0
            c = 0
            a = int(s)
        else:
            flag = not flag
            b = int(s)
            if(a == 0 and b == 0):
                run = False
                break
            count()
            if(operations == 0):
                print("No carry operation.")
            elif operations == 1:
                print("1 carry operation.")
            else:
                print(f"{operations} carry operations.")







0 comments:

張貼留言