#include <iostream> using namespace std; auto char_to_int = [](char x) { return int(x) - int('0'); }; using loong = unsigned long long; #define debug 0 && cout loong solve(string in) { debug << "Solve " << in << endl; if (in.size() == 0) { return 1; } if (in.size() == 1) { return char_to_int(in[0])+1; } auto ptr = in.rbegin(); auto last = *ptr; ptr++; auto prev = *ptr; debug << "(" << prev << ", " << last << ")" << endl; auto value = char_to_int(last); auto value_2 = 10*char_to_int(prev) + value; debug << value << " " << value_2 << endl; loong result = 0; // case 1 - only last letter result += loong(value + 1) * solve(in.substr(0, in.size()-1)); if (value_2 >= 10 && value_2 <= 18) { result += loong(19 - value_2) * solve(in.substr(0, in.size()-2)); } debug << "|" << result << "|" << endl; return result; } int main() { unsigned long long in; cin >> in; std::string s = std::to_string(in); debug << s << endl; cout << solve(s) << 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 58 59 60 | #include <iostream> using namespace std; auto char_to_int = [](char x) { return int(x) - int('0'); }; using loong = unsigned long long; #define debug 0 && cout loong solve(string in) { debug << "Solve " << in << endl; if (in.size() == 0) { return 1; } if (in.size() == 1) { return char_to_int(in[0])+1; } auto ptr = in.rbegin(); auto last = *ptr; ptr++; auto prev = *ptr; debug << "(" << prev << ", " << last << ")" << endl; auto value = char_to_int(last); auto value_2 = 10*char_to_int(prev) + value; debug << value << " " << value_2 << endl; loong result = 0; // case 1 - only last letter result += loong(value + 1) * solve(in.substr(0, in.size()-1)); if (value_2 >= 10 && value_2 <= 18) { result += loong(19 - value_2) * solve(in.substr(0, in.size()-2)); } debug << "|" << result << "|" << endl; return result; } int main() { unsigned long long in; cin >> in; std::string s = std::to_string(in); debug << s << endl; cout << solve(s) << endl; return 0; } |