#include <bits/stdc++.h>
#define nl '\n'
using namespace std;
using ll = long long;
int main()
{
cin.tie(0)->sync_with_stdio(0);
string a, b, c;
cin>>a>>b>>c;
int n = a.size();
vector<int> d(n, 0);
for(int i=0; i<n; i++){
d[i] = a[i] + b[i] - c[i] - '0';
}
d.push_back(2);
ll res = 0;
ll counter = 0;
bool skip_mode = false;
for(int i=0; i<=n; i++){
if(skip_mode){
if(d[i] == 9) continue;
if(d[i] == 10){
counter++;
skip_mode = false;
continue;
}else{
skip_mode = false;
res += counter*(counter+1)/2;
counter = 0;
}
}
if(d[i] == 0){ counter++; }
else if(d[i] == -1){
skip_mode = true;
}else{
res += counter*(counter+1)/2;
counter = 0;
}
}
cout<<res<<nl;
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 | #include <bits/stdc++.h> #define nl '\n' using namespace std; using ll = long long; int main() { cin.tie(0)->sync_with_stdio(0); string a, b, c; cin>>a>>b>>c; int n = a.size(); vector<int> d(n, 0); for(int i=0; i<n; i++){ d[i] = a[i] + b[i] - c[i] - '0'; } d.push_back(2); ll res = 0; ll counter = 0; bool skip_mode = false; for(int i=0; i<=n; i++){ if(skip_mode){ if(d[i] == 9) continue; if(d[i] == 10){ counter++; skip_mode = false; continue; }else{ skip_mode = false; res += counter*(counter+1)/2; counter = 0; } } if(d[i] == 0){ counter++; } else if(d[i] == -1){ skip_mode = true; }else{ res += counter*(counter+1)/2; counter = 0; } } cout<<res<<nl; return 0; } |
English