#include <iostream>
using namespace std;
//#define DEBUG
int main() {
string a, b, c;
cin >> a >> b >> c;
#ifdef DEBUG
cout << a << endl << b << endl << c << endl;
#endif // DEBUG
int i=a.size()-1, carry = 0, endings=0;
long long result = 0;
while (i >= 0) {
#ifdef DEBUG
cout << i << endl;
#endif // DEBUG
int x = a[i] - '0', y = b[i] - '0', z = c[i] - '0';
int sum = x+y+carry;
if (sum % 10 != z) {
#ifdef DEBUG
cout << "LIPA" << endl;
#endif // DEBUG
endings = 0;
if (!carry) i--;
carry = 0;
continue;
}
if (!carry) {
#ifdef DEBUG
cout << "POTENTIAL ENDING" << endl;
#endif // DEBUG
endings++;
}
if (sum < 10) {
#ifdef DEBUG
cout << i << " HAS " << endings << " endings" << endl;
#endif // DEBUG
result += endings;
}
carry = sum / 10;
i--;
}
cout << result << endl;
}
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 | #include <iostream> using namespace std; //#define DEBUG int main() { string a, b, c; cin >> a >> b >> c; #ifdef DEBUG cout << a << endl << b << endl << c << endl; #endif // DEBUG int i=a.size()-1, carry = 0, endings=0; long long result = 0; while (i >= 0) { #ifdef DEBUG cout << i << endl; #endif // DEBUG int x = a[i] - '0', y = b[i] - '0', z = c[i] - '0'; int sum = x+y+carry; if (sum % 10 != z) { #ifdef DEBUG cout << "LIPA" << endl; #endif // DEBUG endings = 0; if (!carry) i--; carry = 0; continue; } if (!carry) { #ifdef DEBUG cout << "POTENTIAL ENDING" << endl; #endif // DEBUG endings++; } if (sum < 10) { #ifdef DEBUG cout << i << " HAS " << endings << " endings" << endl; #endif // DEBUG result += endings; } carry = sum / 10; i--; } cout << result << endl; } |
English