#include <vector>
#include <iostream>
#include <string>
using namespace std;
typedef long long int ll;
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
string a, b, c;
cin >> a >> b >> c;
vector<ll> carries = {0, 0, 0};
ll ans = 0;
for(int i = a.size() - 1; i >= 0; i--){
vector<ll> new_carries = {0, 0, 0};
for(int carry : {0, 1, 2}){
int sum = (a[i] - '0') + (b[i] - '0') + carry;
if(sum % 10 == (c[i] - '0')){
new_carries[sum / 10] += carries[carry];
if(carry == 0){
new_carries[sum / 10] += 1;
}
}
}
carries = new_carries;
ans += carries[0];
}
cout << ans << endl;
return 0;
}
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 | #include <vector> #include <iostream> #include <string> using namespace std; typedef long long int ll; int main() { ios::sync_with_stdio(false); cin.tie(nullptr); string a, b, c; cin >> a >> b >> c; vector<ll> carries = {0, 0, 0}; ll ans = 0; for(int i = a.size() - 1; i >= 0; i--){ vector<ll> new_carries = {0, 0, 0}; for(int carry : {0, 1, 2}){ int sum = (a[i] - '0') + (b[i] - '0') + carry; if(sum % 10 == (c[i] - '0')){ new_carries[sum / 10] += carries[carry]; if(carry == 0){ new_carries[sum / 10] += 1; } } } carries = new_carries; ans += carries[0]; } cout << ans << endl; return 0; } |
English