Python PAT (Basic Level) Practice 1016 部分A+B

Python PAT (Basic Level) Practice 1016 部分A+B_第1张图片

实现代码

def get_result(num1, num2):
    result = 0
    while True:
        flag = 0
        if num1 > 10:
            n = int(num1 % 10)
            num1 = num1 / 10
        else:
            n = int(num1)
            flag = 1
        if n == num2:
            result = result * 10 + n
        if flag == 1:
            break
    return result


if __name__ == '__main__':
    line = input()
    nums = [int(i) for i in line.split(" ")]
    r1 = get_result(nums[0], nums[1])
    r2 = get_result(nums[2], nums[3])
    print(r1 + r2)

你可能感兴趣的:(PAT,Python)