import sys a = "" b = "" ''' try: fin = sys.argv[1] with open(fin, 'r') as fl: a = fl.readline() b = fl.readline() except: sys.exit("Problem z plikiem wejściowym.") a = a[:-1] b = b[:-1]''' a = input() b = input() a = a[::-1] b = b[::-1] komut = 0 if len(a) > len(b): mini = b maxi = a else: mini = a maxi = b del a, b wyn = [] i = 0 while i < len(mini): tmp = int(mini[i]) + int(maxi[i]) + komut if tmp > 9: komut = 1 wyn.append(tmp % 10) else: komut = 0 wyn.append(tmp) i += 1 j = len(mini) while j < len(maxi): tmp = int(maxi[j]) + komut if tmp > 9: komut = 1 wyn.append(tmp % 10) else: komut = 0 wyn.append(tmp) j += 1 if komut == 1: wyn.append(komut) last = wyn[::-1] str_last = "" for i in last: str_last += str(i) print(str_last)
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 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 | import sys a = "" b = "" ''' try: fin = sys.argv[1] with open(fin, 'r') as fl: a = fl.readline() b = fl.readline() except: sys.exit("Problem z plikiem wejściowym.") a = a[:-1] b = b[:-1]''' a = input() b = input() a = a[::-1] b = b[::-1] komut = 0 if len(a) > len(b): mini = b maxi = a else: mini = a maxi = b del a, b wyn = [] i = 0 while i < len(mini): tmp = int(mini[i]) + int(maxi[i]) + komut if tmp > 9: komut = 1 wyn.append(tmp % 10) else: komut = 0 wyn.append(tmp) i += 1 j = len(mini) while j < len(maxi): tmp = int(maxi[j]) + komut if tmp > 9: komut = 1 wyn.append(tmp % 10) else: komut = 0 wyn.append(tmp) j += 1 if komut == 1: wyn.append(komut) last = wyn[::-1] str_last = "" for i in last: str_last += str(i) print(str_last) |