#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
string a,b,c;
cin>>a>>b>>c;
int n=(int)a.size();
long long ans=0;
long long cnt[2]={0,0};
for (int k=n-1; k>=0; k--) {
int ak=a[k]-'0';
int bk=b[k]-'0';
int ck=c[k]-'0';
vector<int> goy(2);
for (int s=0; s<2; s++)
{
int total=ak+bk+s;
if(total%10==ck)
{
goy[s]=total/10;
}
else
{
goy[s]=-1;
}
}
cnt[0]++;
long long cnt1[2]={0,0};
for (int s=0; s<2; s++)
{
if (goy[s]!=-1)
{
cnt1[goy[s]]+=cnt[s];
}
}
cnt[0]=cnt1[0];
cnt[1]=cnt1[1];
ans+=cnt[0];
}
cout<<ans<<"\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 35 36 37 38 39 40 41 42 43 | #include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(0); cin.tie(0); string a,b,c; cin>>a>>b>>c; int n=(int)a.size(); long long ans=0; long long cnt[2]={0,0}; for (int k=n-1; k>=0; k--) { int ak=a[k]-'0'; int bk=b[k]-'0'; int ck=c[k]-'0'; vector<int> goy(2); for (int s=0; s<2; s++) { int total=ak+bk+s; if(total%10==ck) { goy[s]=total/10; } else { goy[s]=-1; } } cnt[0]++; long long cnt1[2]={0,0}; for (int s=0; s<2; s++) { if (goy[s]!=-1) { cnt1[goy[s]]+=cnt[s]; } } cnt[0]=cnt1[0]; cnt[1]=cnt1[1]; ans+=cnt[0]; } cout<<ans<<"\n"; } |
English