#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
string A, B, C;
cin >> A >> B >> C;
int n = A.size();
vector<int> carry(n + 1, 0);
vector<bool> good(n, false);
for (int i = n - 1; i >= 0; i--) {
int a = A[i] - '0';
int b = B[i] - '0';
int c = C[i] - '0';
int sum = a + b + carry[i + 1];
if (sum % 10 == c) {
good[i] = true;
}
carry[i] = sum / 10;
}
long long result = 0;
int i = 0;
while (i < n) {
if (!good[i]) {
i++;
continue;
}
int j = i;
while (j < n && good[j]) j++;
int len = j - i;
int start = i;
for (int k = i; k < j; k++) {
if (carry[k] == 0) {
int end = j - 1;
result += (end - k + 1);
}
}
i = j;
}
cout << result << "\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 | #include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(0); cin.tie(0); string A, B, C; cin >> A >> B >> C; int n = A.size(); vector<int> carry(n + 1, 0); vector<bool> good(n, false); for (int i = n - 1; i >= 0; i--) { int a = A[i] - '0'; int b = B[i] - '0'; int c = C[i] - '0'; int sum = a + b + carry[i + 1]; if (sum % 10 == c) { good[i] = true; } carry[i] = sum / 10; } long long result = 0; int i = 0; while (i < n) { if (!good[i]) { i++; continue; } int j = i; while (j < n && good[j]) j++; int len = j - i; int start = i; for (int k = i; k < j; k++) { if (carry[k] == 0) { int end = j - 1; result += (end - k + 1); } } i = j; } cout << result << "\n"; } |
English