#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> pll;
#define vc vector
#define st first
#define nd second
#define all(a) a.begin(), a.end()
#define sz(a) (ll)a.size()
#define pub push_back
#define pob pop_back
void program() {
vc<ll> a, b, c;
ll n;
string str;
cin >> str;
n = sz(str);
a.resize(n);
b.resize(n);
c.resize(n);
for (ll i = 0; i < n; i++)
a[i] = str[i] - '0';
cin >> str;
for (ll i = 0; i < n; i++)
b[i] = str[i] - '0';
cin >> str;
for (ll i = 0; i < n; i++)
c[i] = str[i] - '0';
vc<ll> git(n), tak(n), giv(n);
for (ll i = 0; i < n; i++) {
if ((a[i] + b[i]) % 10 == c[i])
git[i] = true;
else if ((a[i] + b[i] + 1) % 10 == c[i])
git[i] = tak[i] = true;
giv[i] = a[i] + b[i] + tak[i] >= 10;
}
bool o = false;
ll p = 0;
ll ans = 0;
for (ll i = 0; i < n; i++) {
if (o and git[i] and giv[i]) {
if (tak[i])
continue;
else {
p++;
ans += p;
o = false;
continue;
}
} else if (o) {
p = 0;
o = false;
}
if (not git[i])
p = 0;
else if (not giv[i] and tak[i])
o = true;
else if (not giv[i]) {
p++;
ans += p;
} else
p = 0;
}
cout << ans << "\n";
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
program();
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 | #include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<ll, ll> pll; #define vc vector #define st first #define nd second #define all(a) a.begin(), a.end() #define sz(a) (ll)a.size() #define pub push_back #define pob pop_back void program() { vc<ll> a, b, c; ll n; string str; cin >> str; n = sz(str); a.resize(n); b.resize(n); c.resize(n); for (ll i = 0; i < n; i++) a[i] = str[i] - '0'; cin >> str; for (ll i = 0; i < n; i++) b[i] = str[i] - '0'; cin >> str; for (ll i = 0; i < n; i++) c[i] = str[i] - '0'; vc<ll> git(n), tak(n), giv(n); for (ll i = 0; i < n; i++) { if ((a[i] + b[i]) % 10 == c[i]) git[i] = true; else if ((a[i] + b[i] + 1) % 10 == c[i]) git[i] = tak[i] = true; giv[i] = a[i] + b[i] + tak[i] >= 10; } bool o = false; ll p = 0; ll ans = 0; for (ll i = 0; i < n; i++) { if (o and git[i] and giv[i]) { if (tak[i]) continue; else { p++; ans += p; o = false; continue; } } else if (o) { p = 0; o = false; } if (not git[i]) p = 0; else if (not giv[i] and tak[i]) o = true; else if (not giv[i]) { p++; ans += p; } else p = 0; } cout << ans << "\n"; } int main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); program(); return 0; } |
English