#include <cstdio>
#include <cstdlib>
#include <cstdint>
#include <vector>
#include <map>
#include <algorithm>
#include <set>
#include <time.h>
#include <queue>
using namespace std;
int main () {
vector<char> a, b, c;
char ch;
while (true) {
scanf("%c", &ch);
if (ch < '0' || ch > '9') {
break;
}
a.push_back(ch - '0');
}
int n = a.size();
for (int i = 0; i < n; ++i) {
scanf("%c", &ch);
b.push_back(ch - '0');
}
scanf("%c", &ch);
for (int i = 0; i < n; ++i) {
scanf("%c", &ch);
c.push_back(ch - '0');
}
vector<bool> parts;
char in_long = 0;
for (int i = 0; i < n; ++i) {
char delta = c[i] - a[i] - b[i];
if (delta == 0) {
if (in_long) {
parts.push_back(false);
}
parts.push_back(true);
in_long = false;
}
else if (delta == 1) {
if (in_long) {
parts.push_back(false);
}
in_long = true;
}
else if (delta == -9) {
if (!in_long) {
parts.push_back(false);
}
}
else if (delta == -10) {
parts.push_back(in_long);
in_long = false;
}
else {
in_long = false;
parts.push_back(false);
}
}
/* for (int i = 0; i < parts.size(); ++i) {
printf("%d", parts[i] ? 1 : 0);
}
printf("\n");*/
int cnt = 0;
int64_t res = 0;
for (int i = 0; i < parts.size(); ++i) {
if (parts[i]) {
++cnt;
res += cnt;
}
else {
cnt = 0;
}
}
printf("%lld\n", 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 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 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 | #include <cstdio> #include <cstdlib> #include <cstdint> #include <vector> #include <map> #include <algorithm> #include <set> #include <time.h> #include <queue> using namespace std; int main () { vector<char> a, b, c; char ch; while (true) { scanf("%c", &ch); if (ch < '0' || ch > '9') { break; } a.push_back(ch - '0'); } int n = a.size(); for (int i = 0; i < n; ++i) { scanf("%c", &ch); b.push_back(ch - '0'); } scanf("%c", &ch); for (int i = 0; i < n; ++i) { scanf("%c", &ch); c.push_back(ch - '0'); } vector<bool> parts; char in_long = 0; for (int i = 0; i < n; ++i) { char delta = c[i] - a[i] - b[i]; if (delta == 0) { if (in_long) { parts.push_back(false); } parts.push_back(true); in_long = false; } else if (delta == 1) { if (in_long) { parts.push_back(false); } in_long = true; } else if (delta == -9) { if (!in_long) { parts.push_back(false); } } else if (delta == -10) { parts.push_back(in_long); in_long = false; } else { in_long = false; parts.push_back(false); } } /* for (int i = 0; i < parts.size(); ++i) { printf("%d", parts[i] ? 1 : 0); } printf("\n");*/ int cnt = 0; int64_t res = 0; for (int i = 0; i < parts.size(); ++i) { if (parts[i]) { ++cnt; res += cnt; } else { cnt = 0; } } printf("%lld\n", res); return 0; } |
English