#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define FOR(i,a,b) for(__typeof(b) i = a; i < b; ++i)
#define FORev(i,a,b) for(__typeof(a) i = a; i >= b; --i)
#define ci(x) cin >> x
#define elif else if
signed main(){
ios::sync_with_stdio(0);
cin.tie(0);
string an, bn, cn;
ci(an);ci(bn);ci(cn);
ll siz = an.size();
ll res = 0,end0 = 0,end1 = 0;
vector<ll> a(siz),b(siz),c(siz);
FOR(i,0,siz){
a[i] = an[i] - '0';
b[i] = bn[i] - '0';
c[i] = cn[i] - '0';
}
FORev(i,siz-1,0){
ll cur0 = 0, cur1 = 0;
ll tmp = a[i]+b[i];
if (tmp%10 == c[i]){
ll przen = tmp/10;
if (przen == 0)
cur0 += 1;
elif (przen == 1)
cur1 += 1;
}
if (end0 > 0){
ll tmp1 = tmp;
if (tmp1%10 == c[i]){
ll przen = tmp1/10;
if (przen == 0)
cur0 += end0;
elif (przen == 1)
cur1 += end0;
}
}
if (end1 > 0){
ll tmp2 = tmp+1;
if (tmp2%10 == c[i]){
ll przen = tmp2/10;
if (przen == 0)
cur0 += end1;
elif (przen == 1)
cur1 += end1;
}
}
end0 = cur0;
end1 = cur1;
res += end0;
}
cout << res << "\n";
}
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 | #include <bits/stdc++.h> using namespace std; typedef long long ll; #define FOR(i,a,b) for(__typeof(b) i = a; i < b; ++i) #define FORev(i,a,b) for(__typeof(a) i = a; i >= b; --i) #define ci(x) cin >> x #define elif else if signed main(){ ios::sync_with_stdio(0); cin.tie(0); string an, bn, cn; ci(an);ci(bn);ci(cn); ll siz = an.size(); ll res = 0,end0 = 0,end1 = 0; vector<ll> a(siz),b(siz),c(siz); FOR(i,0,siz){ a[i] = an[i] - '0'; b[i] = bn[i] - '0'; c[i] = cn[i] - '0'; } FORev(i,siz-1,0){ ll cur0 = 0, cur1 = 0; ll tmp = a[i]+b[i]; if (tmp%10 == c[i]){ ll przen = tmp/10; if (przen == 0) cur0 += 1; elif (przen == 1) cur1 += 1; } if (end0 > 0){ ll tmp1 = tmp; if (tmp1%10 == c[i]){ ll przen = tmp1/10; if (przen == 0) cur0 += end0; elif (przen == 1) cur1 += end0; } } if (end1 > 0){ ll tmp2 = tmp+1; if (tmp2%10 == c[i]){ ll przen = tmp2/10; if (przen == 0) cur0 += end1; elif (przen == 1) cur1 += end1; } } end0 = cur0; end1 = cur1; res += end0; } cout << res << "\n"; } |
English