#include <iostream>
#include <vector>
using namespace std;
using ll = long long;
int main()
{
cin.tie(0)->sync_with_stdio();
string a, b, c;
cin>>a>>b>>c;
ll res = 0;
int cur = 0;
bool of = 0;
for(int i=a.size() - 1; i >= 0; i--) {
if(a[i] + b[i] + of == c[i] + '0') {
of = 0;
res += ++cur;
} else if (a[i] + b[i] + of == c[i] + '0' + 10) {
of = 1;
} else if(a[i] + b[i] == c[i] + '0') {
cur = 1;
of = 0;
++res;
} else if(a[i] + b[i] == c[i] + '0' + 10) {
cur = 0;
of = 1;
} else {
cur = 0;
of = 0;
}
}
cout<<res<<"\n";
}
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 | #include <iostream> #include <vector> using namespace std; using ll = long long; int main() { cin.tie(0)->sync_with_stdio(); string a, b, c; cin>>a>>b>>c; ll res = 0; int cur = 0; bool of = 0; for(int i=a.size() - 1; i >= 0; i--) { if(a[i] + b[i] + of == c[i] + '0') { of = 0; res += ++cur; } else if (a[i] + b[i] + of == c[i] + '0' + 10) { of = 1; } else if(a[i] + b[i] == c[i] + '0') { cur = 1; of = 0; ++res; } else if(a[i] + b[i] == c[i] + '0' + 10) { cur = 0; of = 1; } else { cur = 0; of = 0; } } cout<<res<<"\n"; } |
English