#include <iostream>
#include <vector>
// #include "testerka_dod.h"
#define lol long long
using namespace std;
int main() {
string a, b, c;
cin >> a >> b >> c;
int n = a.length();
// for a position i, diff[i] = a+b-c
vector<char> diff(n), diff_w_carry(n);
for (int i = n - 1; i >= 0; i--) {
diff[i] = (a[i] - '0') + (b[i] - '0') - (c[i] - '0');
diff_w_carry[i] = i == n-1 ? diff[n-1] : (diff[i] + diff_w_carry[i + 1] / 10);
}
lol res = 0;
lol starts = 0;
for (int i = n - 1; i >= 0; i--) {
if (diff_w_carry[i] % 10 != 0) starts = 0;
if (diff[i] % 10 == 0) starts++;
if (diff[i] == 0 && diff_w_carry[i] != 0) res++;
if (diff_w_carry[i] == 0) res += starts;
}
cout << res;
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 | #include <iostream> #include <vector> // #include "testerka_dod.h" #define lol long long using namespace std; int main() { string a, b, c; cin >> a >> b >> c; int n = a.length(); // for a position i, diff[i] = a+b-c vector<char> diff(n), diff_w_carry(n); for (int i = n - 1; i >= 0; i--) { diff[i] = (a[i] - '0') + (b[i] - '0') - (c[i] - '0'); diff_w_carry[i] = i == n-1 ? diff[n-1] : (diff[i] + diff_w_carry[i + 1] / 10); } lol res = 0; lol starts = 0; for (int i = n - 1; i >= 0; i--) { if (diff_w_carry[i] % 10 != 0) starts = 0; if (diff[i] % 10 == 0) starts++; if (diff[i] == 0 && diff_w_carry[i] != 0) res++; if (diff_w_carry[i] == 0) res += starts; } cout << res; return 0; } |
English