#include <iostream>
#include <string>
using namespace std;
string s;
bool dw[20];
int xx[100];
int ile(int c, bool dw)
{
int l=s[c]-'0';
if (!dw)
return l+1;
l=l*10+s[c+1]-'0';
return xx[l];
}
long long ile()
{
long long wyn=1;
for (int c=0, w=0; c<s.size(); c+=(dw[w] ? 2 : 1), ++w)
wyn*=ile(c, dw[w]);
return wyn;
}
long long licz(int lc, int ldw)
{
if (s.size()<lc)
return 0;
if (s.size()==lc)
return ile();
long long wyn=0;
dw[ldw]=false;
wyn+=licz(lc+1, ldw+1);
if (lc+1<s.size() && s[lc]!='0')
{
dw[ldw]=true;
wyn+=licz(lc+2, ldw+1);
}
return wyn;
}
int main()
{
for (int a=0; a<10; ++a)
for (int b=0; b<10; ++b)
++xx[a+b];
cin>>s;
cout<<licz(0, 0)<<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 53 | #include <iostream> #include <string> using namespace std; string s; bool dw[20]; int xx[100]; int ile(int c, bool dw) { int l=s[c]-'0'; if (!dw) return l+1; l=l*10+s[c+1]-'0'; return xx[l]; } long long ile() { long long wyn=1; for (int c=0, w=0; c<s.size(); c+=(dw[w] ? 2 : 1), ++w) wyn*=ile(c, dw[w]); return wyn; } long long licz(int lc, int ldw) { if (s.size()<lc) return 0; if (s.size()==lc) return ile(); long long wyn=0; dw[ldw]=false; wyn+=licz(lc+1, ldw+1); if (lc+1<s.size() && s[lc]!='0') { dw[ldw]=true; wyn+=licz(lc+2, ldw+1); } return wyn; } int main() { for (int a=0; a<10; ++a) for (int b=0; b<10; ++b) ++xx[a+b]; cin>>s; cout<<licz(0, 0)<<endl; return 0; } |
English