题解 | #高精度整数加法#
高精度整数加法
https://www.nowcoder.com/practice/49e772ab08994a96980f9618892e55b6
s1 = input().strip() s2 = input().strip() if len(s1) < len(s2): s1, s2 = s2, s1 s2 = s2.rjust(len(s1), '0') res = [] # 进位 carry = 0 for i, j in zip(s1[::-1], s2[::-1]): num = int(i) + int(j) + carry single = num % 10 carry = num // 10 res.append(str(single)) # 最后不等于 0则加上去 if carry != 0: res.append(str(carry)) print(''.join(res[::-1]))