#include<iostream> #include<vector> #include<list> #include<cassert> #include <algorithm> #include <memory> #include <tuple> #include <cmath> #include <map> #include <set> #include <unordered_map> #include <iostream> #include <string> #include <math.h> using namespace std; int TAB[20] = { 1, //0 0+0 2, //1 1+0 3, //2 1+1, 2+0 4, //3 1+2, 3+0 5, //4 1+3m 4+0, 2+2 6, //5 5+0, 4+1, 3+2 7, //6 6+0, 5+1, 4+2, 3+3 8, //7 7+0, 6+1, 5+2, 4+3 9, //8 8+0, 7+1, 6+2, 5+3, 4+4 10, //9 9+0, 8+1, 7+2, 6+3, 5+4, 9, //10 9+1, 8+2, 7+3, 6+4, 5+5 8, //11 9+2, 8+3, 7+4, 6+5 7, //12 9+3, 8+4, 7+5, 6+6 6, //13 9+4, 8+5, 7+6, 5, //14 9+5, 8+6, 7+7 4, //15 9+6, 8+7 3, //16 9+7, 8+8 2, //17 9+8 1, //18 9+9 0 //19 }; int main() { std::string input; cin >> input; unsigned long long res = 0; unsigned long long res1 = 1; unsigned long long res2 = 0; for (int i = input.size() - 1; i >= 0; --i) { int digit = std::stoi(input.substr(i, 1)); int prev_digit = std::stoi(input.substr(i, 2)); res = TAB[digit] * res1 + TAB[prev_digit] * res2; res2 = res1; res1 = res; } cout << res1; 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 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 | #include<iostream> #include<vector> #include<list> #include<cassert> #include <algorithm> #include <memory> #include <tuple> #include <cmath> #include <map> #include <set> #include <unordered_map> #include <iostream> #include <string> #include <math.h> using namespace std; int TAB[20] = { 1, //0 0+0 2, //1 1+0 3, //2 1+1, 2+0 4, //3 1+2, 3+0 5, //4 1+3m 4+0, 2+2 6, //5 5+0, 4+1, 3+2 7, //6 6+0, 5+1, 4+2, 3+3 8, //7 7+0, 6+1, 5+2, 4+3 9, //8 8+0, 7+1, 6+2, 5+3, 4+4 10, //9 9+0, 8+1, 7+2, 6+3, 5+4, 9, //10 9+1, 8+2, 7+3, 6+4, 5+5 8, //11 9+2, 8+3, 7+4, 6+5 7, //12 9+3, 8+4, 7+5, 6+6 6, //13 9+4, 8+5, 7+6, 5, //14 9+5, 8+6, 7+7 4, //15 9+6, 8+7 3, //16 9+7, 8+8 2, //17 9+8 1, //18 9+9 0 //19 }; int main() { std::string input; cin >> input; unsigned long long res = 0; unsigned long long res1 = 1; unsigned long long res2 = 0; for (int i = input.size() - 1; i >= 0; --i) { int digit = std::stoi(input.substr(i, 1)); int prev_digit = std::stoi(input.substr(i, 2)); res = TAB[digit] * res1 + TAB[prev_digit] * res2; res2 = res1; res1 = res; } cout << res1; return 0; } |