l1 = list(input()) l2 = list(input()) if len(l1) > len(l2): l1 = [0] + l1 for i in range(len(l1) - len(l2)): l2 = [0] + l2 else: l2 = [0] + l2 for i in range(len(l2) - len(l1)): l1 = [0] + l1 n = len(l1) for i in range(n): l1[i] = int(l1[i]) l2[i] = int(l2[i]) # print("l1:", l1, "\nl2:", l2) for i in reversed(range(1, n)): l1[i] = l1[i] + l2[i] if l1[i] >= 10: l1[i] = l1[i] % 10 l1[i - 1] += 1 # print(l1) while l1[0] == 0: del(l1[0]) out = "" for i in range(len(l1)): out = out + str(l1[i]) print(out)
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 31 32 33 34 35 | l1 = list(input()) l2 = list(input()) if len(l1) > len(l2): l1 = [0] + l1 for i in range(len(l1) - len(l2)): l2 = [0] + l2 else: l2 = [0] + l2 for i in range(len(l2) - len(l1)): l1 = [0] + l1 n = len(l1) for i in range(n): l1[i] = int(l1[i]) l2[i] = int(l2[i]) # print("l1:", l1, "\nl2:", l2) for i in reversed(range(1, n)): l1[i] = l1[i] + l2[i] if l1[i] >= 10: l1[i] = l1[i] % 10 l1[i - 1] += 1 # print(l1) while l1[0] == 0: del(l1[0]) out = "" for i in range(len(l1)): out = out + str(l1[i]) print(out) |