#include <bits/stdc++.h>
using namespace std;
string a,b,c;
long long n;
long long wyn=0;
long long strt=0;
long long carry=0;
long long st=-1;
int main(){
cin.tie(0)->sync_with_stdio(0);
cin >> a >> b >> c;
n=a.size();
for(int i=n-1;i>=0;i--){
int x = a[i]-'0';
int y = b[i]-'0';
int z = x+y;
if(st==-1){
if(('0'+z%10)==c[i]){
st=i;
if(z>=10){
carry=1;
strt++;
}
else{
wyn++;
strt++;
}
}
}
else{
if(carry){
if(('0'+(z%10+1)%10)==c[i]){
//cout << "CARRY T " << i << '\n';
if((z+1)>=10){
carry=1;
}
else{
wyn+=strt;
carry=0;
}
}
else{
strt=0;
carry=0;
st=-1;
if(('0'+z%10)==c[i]){
st=i;
if(z>=10){
carry=1;
strt++;
}
else{
wyn++;
strt++;
}
}
}
}
else{
if(('0'+z%10)==c[i]){
if(z>=10){
carry=1;
strt++;
}
else{
carry=0;
strt++;
wyn+=strt;
}
}
else{
strt=0;
carry=0;
st=-1;
}
}
}
// cout << i << ": " << '\n';
// cout << "Carry: " << carry << '\n';
// cout << "Starts: " << strt << '\n';
// cout << "St: " << st << '\n';
// cout << "Z: " << z << '\n';
}
cout << wyn;
}
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 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 | #include <bits/stdc++.h> using namespace std; string a,b,c; long long n; long long wyn=0; long long strt=0; long long carry=0; long long st=-1; int main(){ cin.tie(0)->sync_with_stdio(0); cin >> a >> b >> c; n=a.size(); for(int i=n-1;i>=0;i--){ int x = a[i]-'0'; int y = b[i]-'0'; int z = x+y; if(st==-1){ if(('0'+z%10)==c[i]){ st=i; if(z>=10){ carry=1; strt++; } else{ wyn++; strt++; } } } else{ if(carry){ if(('0'+(z%10+1)%10)==c[i]){ //cout << "CARRY T " << i << '\n'; if((z+1)>=10){ carry=1; } else{ wyn+=strt; carry=0; } } else{ strt=0; carry=0; st=-1; if(('0'+z%10)==c[i]){ st=i; if(z>=10){ carry=1; strt++; } else{ wyn++; strt++; } } } } else{ if(('0'+z%10)==c[i]){ if(z>=10){ carry=1; strt++; } else{ carry=0; strt++; wyn+=strt; } } else{ strt=0; carry=0; st=-1; } } } // cout << i << ": " << '\n'; // cout << "Carry: " << carry << '\n'; // cout << "Starts: " << strt << '\n'; // cout << "St: " << st << '\n'; // cout << "Z: " << z << '\n'; } cout << wyn; } |
English