import sys def additionInTheBar(a, b): a = list(a) b = list(b) a.reverse() b.reverse() c = [] carry = 0 for i in range(max(len(a), len(b))): if i < len(a): carry += int(a[i]) if i < len(b): carry += int(b[i]) c.append(str(carry % 10)) carry = carry // 10 if carry > 0: c.append(str(carry)) c.reverse() return ''.join(c) def main(): a = sys.stdin.readline().strip() b = sys.stdin.readline().strip() print(additionInTheBar(a, b)) main()
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 | import sys def additionInTheBar(a, b): a = list(a) b = list(b) a.reverse() b.reverse() c = [] carry = 0 for i in range(max(len(a), len(b))): if i < len(a): carry += int(a[i]) if i < len(b): carry += int(b[i]) c.append(str(carry % 10)) carry = carry // 10 if carry > 0: c.append(str(carry)) c.reverse() return ''.join(c) def main(): a = sys.stdin.readline().strip() b = sys.stdin.readline().strip() print(additionInTheBar(a, b)) main() |