#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cstdlib>
using namespace std;
int main(){
ios::sync_with_stdio(false);
cin.tie(nullptr);
string s1, s2, s3;
cin >> s1 >> s2 >> s3;
int n = (int)s1.size();
long long out = 0;
long long x = 0, y = 0;
int it = n - 1;
while(it >= 0){
int calc = (int)(s1[it]-'0') + (int)(s2[it]-'0') - (int)(s3[it]-'0');
if(calc == 0){
x = x + 1;
y = 0;
out += x;
}
else if(calc == 10){
y = x + 1;
x = 0;
}
else if(calc == -1){
x = y;
y = 0;
out += x;
}
else if(calc == 9){
x = 0;
}
else{
x = 0;
y = 0;
}
--it;
}
cout << out;
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 | #include <iostream> #include <string> #include <algorithm> #include <vector> #include <cstdlib> using namespace std; int main(){ ios::sync_with_stdio(false); cin.tie(nullptr); string s1, s2, s3; cin >> s1 >> s2 >> s3; int n = (int)s1.size(); long long out = 0; long long x = 0, y = 0; int it = n - 1; while(it >= 0){ int calc = (int)(s1[it]-'0') + (int)(s2[it]-'0') - (int)(s3[it]-'0'); if(calc == 0){ x = x + 1; y = 0; out += x; } else if(calc == 10){ y = x + 1; x = 0; } else if(calc == -1){ x = y; y = 0; out += x; } else if(calc == 9){ x = 0; } else{ x = 0; y = 0; } --it; } cout << out; return 0; } |
English