题解 | #高精度整数加法#
高精度整数加法
http://www.nowcoder.com/practice/49e772ab08994a96980f9618892e55b6
a = input()
b = input()
if len(b) <= len(a):
b = b.rjust(len(a),"0")
else:
a = a.rjust(len(b),"0")
#先对齐补位
c = list(map(int,a[::-1]))
d = list(map(int,b[::-1]))
逆序按位相加
e = []
tag = 0 # 进位标志
for i in range(len(c)):
if c[i] + d[i] + tag > 9:
e.append(c[i] + d[i] + tag - 10)
tag = 1
else:
e.append(c[i] + d[i] + tag)
tag = 0
if tag: #溢出判断,最后溢出了则补1
e.append(1)
print("".join([str(x) for x in e[::-1]]))