#include <iostream> #include <string> int64_t comb(const std::string& num) { int64_t curr = int64_t(num.at(0)) - '0' + 1; int64_t prevprev = 1; int64_t prev = curr; for (size_t i = 2; i < num.length() + 1; i++) { int64_t dig = int64_t(num.at(i - 1)) - '0'; curr = (dig + 1) * prev; if (num.at(i - 2) == '1') { curr += (10 - dig - 1) * prevprev; } prevprev = prev; prev = curr; } return curr; } int main() { std::string num = std::string(); std::cin >> num; std::cout << comb(num) << std::flush; 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 | #include <iostream> #include <string> int64_t comb(const std::string& num) { int64_t curr = int64_t(num.at(0)) - '0' + 1; int64_t prevprev = 1; int64_t prev = curr; for (size_t i = 2; i < num.length() + 1; i++) { int64_t dig = int64_t(num.at(i - 1)) - '0'; curr = (dig + 1) * prev; if (num.at(i - 2) == '1') { curr += (10 - dig - 1) * prevprev; } prevprev = prev; prev = curr; } return curr; } int main() { std::string num = std::string(); std::cin >> num; std::cout << comb(num) << std::flush; return 0; } |