#include <bits/stdc++.h>
#define F(i, a, b) for(int i = a; i <= b; i++)
#define R(i, a, b) for(int i = a; i >= b; i--)
#define pb push_back
#define be(X) X.begin(), X.end()
#define pii pair<int,int>
#define V vector
#define f first
#define s second
#define int long long
using namespace std;
int32_t main() {
ios::sync_with_stdio(0);
cin.tie(0);
string a, b, c;
cin >> a >> b >> c;
int w1 = 0, w2 = 0;
int ans = 0;
R(i, (int)a.size()-1, 0){
int w11 = 0, w21 = 0;
int roz = (a[i] - '0') + (b[i] - '0') - (c[i] - '0');
if(roz == 0){
w11 = w1 + 1;
}
if(roz == -1){
w11 = w2;
}
if(roz == 9){
w21 = w2;
}
if(roz == 10){
w21 = w1 + 1;
}
w1 = w11;
w2 = w21;
ans += w1;
}
cout << ans;
}
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 | #include <bits/stdc++.h> #define F(i, a, b) for(int i = a; i <= b; i++) #define R(i, a, b) for(int i = a; i >= b; i--) #define pb push_back #define be(X) X.begin(), X.end() #define pii pair<int,int> #define V vector #define f first #define s second #define int long long using namespace std; int32_t main() { ios::sync_with_stdio(0); cin.tie(0); string a, b, c; cin >> a >> b >> c; int w1 = 0, w2 = 0; int ans = 0; R(i, (int)a.size()-1, 0){ int w11 = 0, w21 = 0; int roz = (a[i] - '0') + (b[i] - '0') - (c[i] - '0'); if(roz == 0){ w11 = w1 + 1; } if(roz == -1){ w11 = w2; } if(roz == 9){ w21 = w2; } if(roz == 10){ w21 = w1 + 1; } w1 = w11; w2 = w21; ans += w1; } cout << ans; } |
English