#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
string A, B, C;
cin >> A >> B >> C;
int64_t ans = 0;
int good = 0, almost = 0;
for (int i = 0; i < (int)A.size(); ++i) {
int a = A[i] - '0', b = B[i] - '0', c = C[i] - '0';
if (a + b == c) {
good += 1;
ans += good;
almost = 0;
}
else if (a + b == 10 + c) {
// good = good;
ans += almost;
good = almost;
almost = 0;
}
else if (a + b == c - 1) {
almost = good + 1;
good = 0;
}
else if (a + b == 10 + c - 1) {
// almost = almost;
good = 0;
}
else {
good = almost = 0;
}
}
cout << ans << '\n';
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 <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); string A, B, C; cin >> A >> B >> C; int64_t ans = 0; int good = 0, almost = 0; for (int i = 0; i < (int)A.size(); ++i) { int a = A[i] - '0', b = B[i] - '0', c = C[i] - '0'; if (a + b == c) { good += 1; ans += good; almost = 0; } else if (a + b == 10 + c) { // good = good; ans += almost; good = almost; almost = 0; } else if (a + b == c - 1) { almost = good + 1; good = 0; } else if (a + b == 10 + c - 1) { // almost = almost; good = 0; } else { good = almost = 0; } } cout << ans << '\n'; return 0; } |
English