题解 | #高精度整数加法#
高精度整数加法
https://www.nowcoder.com/practice/49e772ab08994a96980f9618892e55b6
i1 = input() i2 = input() # print(int(i1) + int(i2)) i1 = list(i1)[::-1] i2 = list(i2)[::-1] l = max(len(i1), len(i2)) outList = [] addSet = 0 for i in range(l): if not i1: n1 = 0 n2 = int(i2.pop(0)) elif not i2: n1 = int(i1.pop(0)) n2 = 0 else: n1 = int(i1.pop(0)) n2 = int(i2.pop(0)) curNum = n1 + n2 + addSet addSet = curNum // 10 curStr = str(curNum % 10) outList.append(curStr) if addSet: outList.append(str(addSet)) print("".join(outList[::-1]))