题解 | #高精度整数加法#
高精度整数加法
https://www.nowcoder.com/practice/49e772ab08994a96980f9618892e55b6
while True:
try:
a,b = str(input()),str(input())
s1, s2 = [i for i in a], [j for j in b]
res= ["0"]
flag = 0
if len(s1) < len(s2):
s1 = ["0"] * (len(s2)-len(s1)) + s1
else:
s2 = ["0"] *(len(s1)-len(s2)) + s2
while s1 and s2:
sum_ = int(s1.pop()) + int(s2.pop()) + flag
flag = int(sum_ /10)
res.insert(0,str(sum_ % 10))
if flag:
res.insert(0,str(flag))
print("".join(res[:-1]))
except:
break
try:
a,b = str(input()),str(input())
s1, s2 = [i for i in a], [j for j in b]
res= ["0"]
flag = 0
if len(s1) < len(s2):
s1 = ["0"] * (len(s2)-len(s1)) + s1
else:
s2 = ["0"] *(len(s1)-len(s2)) + s2
while s1 and s2:
sum_ = int(s1.pop()) + int(s2.pop()) + flag
flag = int(sum_ /10)
res.insert(0,str(sum_ % 10))
if flag:
res.insert(0,str(flag))
print("".join(res[:-1]))
except:
break