#include <iostream> #include <vector> typedef long long ll; ll single_dig(ll digit) { return digit + 1; } ll double_dig(ll digit) { return 9 - digit; } int main() { ll a; std::cin >> a; std::vector<int> digits; while (a) { digits.push_back(a % 10); a /= 10; } ll* total = new ll[digits.size() + 1]; total[0] = 1; for (unsigned long i = 0; i < digits.size(); i++) { total[i + 1] = total[i] * single_dig(digits[i]); if (i > 0 && digits[i] == 1) { total[i + 1] += total[i - 1] * double_dig(digits[i - 1]); } } std::cout << total[digits.size()] << std::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 | #include <iostream> #include <vector> typedef long long ll; ll single_dig(ll digit) { return digit + 1; } ll double_dig(ll digit) { return 9 - digit; } int main() { ll a; std::cin >> a; std::vector<int> digits; while (a) { digits.push_back(a % 10); a /= 10; } ll* total = new ll[digits.size() + 1]; total[0] = 1; for (unsigned long i = 0; i < digits.size(); i++) { total[i + 1] = total[i] * single_dig(digits[i]); if (i > 0 && digits[i] == 1) { total[i + 1] += total[i - 1] * double_dig(digits[i - 1]); } } std::cout << total[digits.size()] << std::endl; return 0; } |