#include <iostream> #include <cstring> using namespace std; string n; long long getCombinations(int it) { if (n.length() == it) return 1; if (n.length() - 1 == it) return (n[it] - '0' + 1); long long double_digit = 0; if (n[it] == '1' && n[it + 1] < '9') { double_digit = (9 - (n[it + 1] - '0')) * getCombinations(it + 2); } return (n[it] + 1 - '0') * getCombinations(it + 1) + double_digit; } int main() { ios_base::sync_with_stdio(false); cin.tie(0); cin >> n; cout << getCombinations(0) << "\n"; 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 | #include <iostream> #include <cstring> using namespace std; string n; long long getCombinations(int it) { if (n.length() == it) return 1; if (n.length() - 1 == it) return (n[it] - '0' + 1); long long double_digit = 0; if (n[it] == '1' && n[it + 1] < '9') { double_digit = (9 - (n[it + 1] - '0')) * getCombinations(it + 2); } return (n[it] + 1 - '0') * getCombinations(it + 1) + double_digit; } int main() { ios_base::sync_with_stdio(false); cin.tie(0); cin >> n; cout << getCombinations(0) << "\n"; return 0; } |