#include <algorithm>
#include <iostream>
#include <queue>
#include <vector>
using namespace std;
typedef long long ll;
string a, b, c;
int main() {
std::ios_base::sync_with_stdio(false);
std::cin.tie(NULL);
cin >> a >> b >> c;
int L = a.length();
int cc = 0;
int ch = 0;
ll res = 0;
for (int i = L - 1; i >= 0; i--) {
int ai = a[i] - '0';
int bi = b[i] - '0';
int ci = c[i] - '0';
int ss = ai + bi;
if (cc) {
if (ss + cc == ci) {
ch++;
res += ch;
cc = 0;
} else if (ss + cc - 10 == ci) {
} else if (ss == ci) {
cc = 0;
ch = 1;
res += ch;
} else if (ss - 10 == ci) {
ch = 0;
} else {
cc = 0;
ch = 0;
}
} else {
if (ss == ci) {
ch++;
res += ch;
} else if (ss - 10 == ci) {
cc = 1;
} else {
ch = 0;
cc = 0;
}
}
}
cout << res << "\n";
cout.flush();
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 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 | #include <algorithm> #include <iostream> #include <queue> #include <vector> using namespace std; typedef long long ll; string a, b, c; int main() { std::ios_base::sync_with_stdio(false); std::cin.tie(NULL); cin >> a >> b >> c; int L = a.length(); int cc = 0; int ch = 0; ll res = 0; for (int i = L - 1; i >= 0; i--) { int ai = a[i] - '0'; int bi = b[i] - '0'; int ci = c[i] - '0'; int ss = ai + bi; if (cc) { if (ss + cc == ci) { ch++; res += ch; cc = 0; } else if (ss + cc - 10 == ci) { } else if (ss == ci) { cc = 0; ch = 1; res += ch; } else if (ss - 10 == ci) { ch = 0; } else { cc = 0; ch = 0; } } else { if (ss == ci) { ch++; res += ch; } else if (ss - 10 == ci) { cc = 1; } else { ch = 0; cc = 0; } } } cout << res << "\n"; cout.flush(); return 0; } |
English