#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
#include <cmath>
#include <string>
#include <queue>
#include <numeric>
using namespace std;
using ll = long long;
int main() {
string A, B, C;
cin >> A >> B >> C;
int n = A.size();
for (int i = 0; i < n; i++) {
A[i] -= '0';
B[i] -= '0';
C[i] -= '0';
C[i] = A[i] + B[i] - C[i];
}
int j = n - 1;
ll res = 0;
int ends = 0;
while (j >= 0) {
while (j >= 0 && C[j] == 0) {
ends++;
j--;
res += ends;
}
bool t = false;
if (j >= 0 && C[j] == 10) {
t = true;
j--;
}
while (j >= 0 && C[j] == 9) {
j--;
}
if (j >= 0 && C[j] == -1 && t) {
ends++;
res += ends;
j--;
} else {
ends = 0;
if (j < 0 || C[j] % 10 != 0) {
j--;
}
}
}
cout << res << 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 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 | #include <iostream> #include <vector> #include <algorithm> #include <map> #include <set> #include <cmath> #include <string> #include <queue> #include <numeric> using namespace std; using ll = long long; int main() { string A, B, C; cin >> A >> B >> C; int n = A.size(); for (int i = 0; i < n; i++) { A[i] -= '0'; B[i] -= '0'; C[i] -= '0'; C[i] = A[i] + B[i] - C[i]; } int j = n - 1; ll res = 0; int ends = 0; while (j >= 0) { while (j >= 0 && C[j] == 0) { ends++; j--; res += ends; } bool t = false; if (j >= 0 && C[j] == 10) { t = true; j--; } while (j >= 0 && C[j] == 9) { j--; } if (j >= 0 && C[j] == -1 && t) { ends++; res += ends; j--; } else { ends = 0; if (j < 0 || C[j] % 10 != 0) { j--; } } } cout << res << endl; return 0; } |
English