liczba1 = input().strip()
liczba2 = input().strip()
wynik = input().strip()
n = len(liczba1)
dp0 = 0
dp1 = 0
ile = 0
for i in range(n - 1, -1, -1):
a = ord(liczba1[i]) - 48
b = ord(liczba2[i]) - 48
c = ord(wynik[i]) - 48
suma0 = a + b
suma1 = a + b + 1
pasuje0 = (suma0 % 10 == c)
pasuje1 = (suma1 % 10 == c)
nowe_dp0 = 0
nowe_dp1 = 0
if pasuje0:
if suma0 < 10:
nowe_dp0 += 1
else:
nowe_dp1 += 1
if pasuje0:
if suma0 < 10:
nowe_dp0 += dp0
else:
nowe_dp1 += dp0
if pasuje1:
if suma1 < 10:
nowe_dp0 += dp1
else:
nowe_dp1 += dp1
dp0 = nowe_dp0
dp1 = nowe_dp1
ile += dp0
print(ile)
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 | liczba1 = input().strip() liczba2 = input().strip() wynik = input().strip() n = len(liczba1) dp0 = 0 dp1 = 0 ile = 0 for i in range(n - 1, -1, -1): a = ord(liczba1[i]) - 48 b = ord(liczba2[i]) - 48 c = ord(wynik[i]) - 48 suma0 = a + b suma1 = a + b + 1 pasuje0 = (suma0 % 10 == c) pasuje1 = (suma1 % 10 == c) nowe_dp0 = 0 nowe_dp1 = 0 if pasuje0: if suma0 < 10: nowe_dp0 += 1 else: nowe_dp1 += 1 if pasuje0: if suma0 < 10: nowe_dp0 += dp0 else: nowe_dp1 += dp0 if pasuje1: if suma1 < 10: nowe_dp0 += dp1 else: nowe_dp1 += dp1 dp0 = nowe_dp0 dp1 = nowe_dp1 ile += dp0 print(ile) |
English