#include <iostream>
#include <string>
using namespace std;
typedef long long LL;
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
LL wyn=0;
string a, b, c;
cin>>a>>b>>c;
LL bp=0, zp=0;
for (int i=a.size()-1; 0<=i; --i)
{
int aa=a[i]-'0';
int bb=b[i]-'0';
int cc=c[i]-'0';
if (aa+bb==cc)
{
++bp;
wyn+=bp;
zp=0;
}
else if (aa+bb+1==cc)
{
wyn+=zp;
bp=zp;
zp=0;
}
else if (aa+bb==cc+10)
{
zp=bp+1;
bp=0;
}
else if (aa+bb+1==cc+10)
{
bp=0;
}
else
{
bp=zp=0;
}
}
cout<<wyn<<endl;
return 0;
}
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 | #include <iostream> #include <string> using namespace std; typedef long long LL; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); LL wyn=0; string a, b, c; cin>>a>>b>>c; LL bp=0, zp=0; for (int i=a.size()-1; 0<=i; --i) { int aa=a[i]-'0'; int bb=b[i]-'0'; int cc=c[i]-'0'; if (aa+bb==cc) { ++bp; wyn+=bp; zp=0; } else if (aa+bb+1==cc) { wyn+=zp; bp=zp; zp=0; } else if (aa+bb==cc+10) { zp=bp+1; bp=0; } else if (aa+bb+1==cc+10) { bp=0; } else { bp=zp=0; } } cout<<wyn<<endl; return 0; } |
English