#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
using namespace std;
#define ll unsigned long long
string a, b, c;
int main()
{
ios::sync_with_stdio(0);
cin.tie(nullptr);
cin >> a >> b >> c;
int n = a.size();
int w = 0;
for (int i = n - 1; i >= 0; i--)
{
int x, y, s, p = 0;
if ((a[i] - '0' + b[i] - '0') % 10 == c[i] - '0')
{
for (int j = i; j >= 0; j--)
{
x = (a[j] - '0');
y = (b[j] - '0');
s = x + y + p;
p = s / 10;
//cout << s << " " << c[j] << endl;
if (((char)'0' + s) == c[j])
w++;
else if (((char)'0' + s % 10) == c[j])
{
}
else
break;
}
}
}
cout << w;
}
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 <iostream> #include <algorithm> #include <string> #include <vector> using namespace std; #define ll unsigned long long string a, b, c; int main() { ios::sync_with_stdio(0); cin.tie(nullptr); cin >> a >> b >> c; int n = a.size(); int w = 0; for (int i = n - 1; i >= 0; i--) { int x, y, s, p = 0; if ((a[i] - '0' + b[i] - '0') % 10 == c[i] - '0') { for (int j = i; j >= 0; j--) { x = (a[j] - '0'); y = (b[j] - '0'); s = x + y + p; p = s / 10; //cout << s << " " << c[j] << endl; if (((char)'0' + s) == c[j]) w++; else if (((char)'0' + s % 10) == c[j]) { } else break; } } } cout << w; } |
English