#include <bits/stdc++.h>
using namespace std;
string S1, S2, E1;
int s, c, p = INT_MIN;
long long res;
// inline long long poprawne(string& f, string& g, string& h){
// long long r = 0;
// for (int i = 0; i < f.size(); i++){
// for (int j = i; j < f.size(); j++){
// long long A = stoll((f.substr(i, j-i+1)).c_str());
// long long B = stoll((g.substr(i, j-i+1)).c_str());
// long long C = stoll((h.substr(i, j-i+1)).c_str());
// if (A + B == C)
// r++;
// }
// }
// return r;
// }
int main(){
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
cin >> S1 >> S2 >> E1;
for (int i = 0; i < S2.size(); i++){
c = (E1[i] - S1[i] - S2[i] + '0');
if (c == 0){
if (p == 1 || p == -9){
s = 0;
}
p = c;
s++;
res += s;
}else if (c == -10){
if (p == -10 || p == 0) {
s = 0;
}
res += s;
p = c;
}else if (c == 1){
if (p == -9 || p == 1){
s = 0;
}
s++;
p = c;
}else if (c == -9){
if (p == 0 || p == -10){
s = 0;
}
p = c;
}else{
s = 0;
p = INT_MIN;
}
}
// int r = poprawne(S1, S2, E1);
// if (r == res) {
cout << res << '\n';
// }else {
// cerr << "WA\n" << "POPR " << r << "\nZLE " << 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 | #include <bits/stdc++.h> using namespace std; string S1, S2, E1; int s, c, p = INT_MIN; long long res; // inline long long poprawne(string& f, string& g, string& h){ // long long r = 0; // for (int i = 0; i < f.size(); i++){ // for (int j = i; j < f.size(); j++){ // long long A = stoll((f.substr(i, j-i+1)).c_str()); // long long B = stoll((g.substr(i, j-i+1)).c_str()); // long long C = stoll((h.substr(i, j-i+1)).c_str()); // if (A + B == C) // r++; // } // } // return r; // } int main(){ ios_base::sync_with_stdio(false); cin.tie(nullptr); cin >> S1 >> S2 >> E1; for (int i = 0; i < S2.size(); i++){ c = (E1[i] - S1[i] - S2[i] + '0'); if (c == 0){ if (p == 1 || p == -9){ s = 0; } p = c; s++; res += s; }else if (c == -10){ if (p == -10 || p == 0) { s = 0; } res += s; p = c; }else if (c == 1){ if (p == -9 || p == 1){ s = 0; } s++; p = c; }else if (c == -9){ if (p == 0 || p == -10){ s = 0; } p = c; }else{ s = 0; p = INT_MIN; } } // int r = poprawne(S1, S2, E1); // if (r == res) { cout << res << '\n'; // }else { // cerr << "WA\n" << "POPR " << r << "\nZLE " << res; // } return 0; } |
English