#include <iostream> using u8 = unsigned char; using u64 = unsigned long long; const u8 permutations[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1}; u8 get_permutation(const std::string& number, int index, bool is_double) { if (is_double) { switch (number[index] - 48) { case 0: return permutations[number[index + 1] - 48]; case 1: return permutations[number[index + 1] - 38]; default: return 0; } } else { return permutations[number[index] - 48]; } } int main() { std::ios_base::sync_with_stdio(false); std::cin.tie(0); std::string number; std::cin >> number; int penultimate = 1; int ultimate = get_permutation(number, 0, false); for (int i = 1; i < number.size(); i++) { int temp = get_permutation(number, i - 1, true) * penultimate + get_permutation(number, i, false) * ultimate; penultimate = ultimate; ultimate = temp; } std::cout << ultimate; }
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 | #include <iostream> using u8 = unsigned char; using u64 = unsigned long long; const u8 permutations[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1}; u8 get_permutation(const std::string& number, int index, bool is_double) { if (is_double) { switch (number[index] - 48) { case 0: return permutations[number[index + 1] - 48]; case 1: return permutations[number[index + 1] - 38]; default: return 0; } } else { return permutations[number[index] - 48]; } } int main() { std::ios_base::sync_with_stdio(false); std::cin.tie(0); std::string number; std::cin >> number; int penultimate = 1; int ultimate = get_permutation(number, 0, false); for (int i = 1; i < number.size(); i++) { int temp = get_permutation(number, i - 1, true) * penultimate + get_permutation(number, i, false) * ultimate; penultimate = ultimate; ultimate = temp; } std::cout << ultimate; } |