import fileinput f = fileinput.input() a = f.readline() b = f.readline() if len(a) > len(b) : b = '0' * (len(a) - len(b)) + b else : a = '0' * (len(b) - len(a)) + a a_b = "" add = 0 for ac, bc in zip(reversed(a.strip()), reversed(b.strip())): a_b += str((int(ac) + int(bc) + add) % 10) add = (int(ac) + int(bc) + add) // 10 res = "" for x in reversed(a_b): res += x print(res)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 | import fileinput f = fileinput.input() a = f.readline() b = f.readline() if len(a) > len(b) : b = '0' * (len(a) - len(b)) + b else : a = '0' * (len(b) - len(a)) + a a_b = "" add = 0 for ac, bc in zip(reversed(a.strip()), reversed(b.strip())): a_b += str((int(ac) + int(bc) + add) % 10) add = (int(ac) + int(bc) + add) // 10 res = "" for x in reversed(a_b): res += x print(res) |