题解 | #Primary Arithmetic#

Primary Arithmetic

https://www.nowcoder.com/practice/c1fb44e931394e6693671f49c899f5de

def fun(a):
    res = []
    while a >0:
        t = a % 10
        a = a / 10
        res.append(t)
    return res

def add(a, b):
    a = fun(a)
    b = fun(b)
    i, j = 0, 0
    c = 0
    while i < len(a) and j < len(b):
        if a[i] + b[j] >= 10:
            c+=1
        i+=1
        j+=1
    return c

while True:
    try:
        a, b = map(int, input().split())
        if a == 0 and b == 0:
            break
        res = add(a, b)
        if res == 0:
            print("NO carry operation.")
        elif res == 1:
            print("%d carry operation."%(res))
        else:
            print("%d carry operations."%(res))
    except:
        break

全部评论

相关推荐

牛客小菜鸡66:boss里面,招人的叫老板,找工作的叫牛人
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务