#include <cstdio> #include <cmath> using namespace std; int combinations1(int x) { return x <= 9 ? -abs(x - 9) + 10 : 0; } int combinations2(int x) { return x >= 10 && x <= 18 ? -abs(x - 9) + 10 : 0; } int main() { unsigned long long n; unsigned long long result[20] = {1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; int i = 1; scanf("%lld", &n); while(n) { result[i] += combinations1(n%10) * result[i-1]; result[i+1] += combinations2(n%100) * result[i-1]; i++; n /= 10; } printf("%lld\n", result[i-1]); }
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 <cstdio> #include <cmath> using namespace std; int combinations1(int x) { return x <= 9 ? -abs(x - 9) + 10 : 0; } int combinations2(int x) { return x >= 10 && x <= 18 ? -abs(x - 9) + 10 : 0; } int main() { unsigned long long n; unsigned long long result[20] = {1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; int i = 1; scanf("%lld", &n); while(n) { result[i] += combinations1(n%10) * result[i-1]; result[i+1] += combinations2(n%100) * result[i-1]; i++; n /= 10; } printf("%lld\n", result[i-1]); } |