#include <iostream>
using namespace std;
int howManyOptionForNumber(int number)
{
if(number > 18)
return 0;
if(number < 10)
return number + 1;
return 19 - number;
}
int howManyOptions(string number)
{
if(number.empty())
return 1;
if(number.size() == 1)
return howManyOptionForNumber(stoi(number));
int result = 0;
int lastDigit = int(number[number.size() - 1]) - 48;
number.pop_back();
int twoLastDigits = lastDigit + 10*(int(number[number.size() - 1]) - 48);
int amountOfOptionsForTwoLastDigits = howManyOptionForNumber(twoLastDigits);
if(twoLastDigits == 0)
amountOfOptionsForTwoLastDigits = 0;
int amountOfOptionsForLastDigit = howManyOptionForNumber(lastDigit);
int a = 0;
int b = 0;
if(amountOfOptionsForLastDigit > 0)
a = amountOfOptionsForLastDigit * howManyOptions(number);
number.pop_back();
if(amountOfOptionsForTwoLastDigits > 0)
b = amountOfOptionsForTwoLastDigits * howManyOptions(number);
// cout<< a << " "<< b<<endl;
return a + b;
}
int multipliesDigits(int i)
{
if(i < 10)
return i + 1;
return ((i%10)+1 ) * multipliesDigits(i/100);
}
int main() {
ios_base::sync_with_stdio(false);
string number;
cin >> number;
// for(int i = 0; i < 1000; i++)
// if(howManyOptions(to_string(i)) != multipliesDigits(i))
// cout<<i<<" " <<howManyOptions(to_string(i))<<" "<< multipliesDigits(i)<<endl;
cout<< howManyOptions(number)<<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 54 55 56 57 | #include <iostream> using namespace std; int howManyOptionForNumber(int number) { if(number > 18) return 0; if(number < 10) return number + 1; return 19 - number; } int howManyOptions(string number) { if(number.empty()) return 1; if(number.size() == 1) return howManyOptionForNumber(stoi(number)); int result = 0; int lastDigit = int(number[number.size() - 1]) - 48; number.pop_back(); int twoLastDigits = lastDigit + 10*(int(number[number.size() - 1]) - 48); int amountOfOptionsForTwoLastDigits = howManyOptionForNumber(twoLastDigits); if(twoLastDigits == 0) amountOfOptionsForTwoLastDigits = 0; int amountOfOptionsForLastDigit = howManyOptionForNumber(lastDigit); int a = 0; int b = 0; if(amountOfOptionsForLastDigit > 0) a = amountOfOptionsForLastDigit * howManyOptions(number); number.pop_back(); if(amountOfOptionsForTwoLastDigits > 0) b = amountOfOptionsForTwoLastDigits * howManyOptions(number); // cout<< a << " "<< b<<endl; return a + b; } int multipliesDigits(int i) { if(i < 10) return i + 1; return ((i%10)+1 ) * multipliesDigits(i/100); } int main() { ios_base::sync_with_stdio(false); string number; cin >> number; // for(int i = 0; i < 1000; i++) // if(howManyOptions(to_string(i)) != multipliesDigits(i)) // cout<<i<<" " <<howManyOptions(to_string(i))<<" "<< multipliesDigits(i)<<endl; cout<< howManyOptions(number)<<endl; return 0; } |
English