#include <iostream> #include <bits/stdc++.h> #include <algorithm> #include <vector> #include <cmath> using namespace std; long conv( int i) { return static_cast<long>(10 - std::abs(i-9)); } long numberof(std::vector<int> v) { long answer = 1L; if (v.size() == 0) return 1; if (v.size() == 1) return conv(v.at(0)); for (std::vector<int>::iterator it = v.begin(); it != v.end(); it++) { answer *= conv(*it); } for (std::vector<int>::iterator it = v.begin()+1; it != v.end(); it++) { if (*it ==1 && *(it-1)<9) { std::vector<int> n,m; std::copy(it+1, v.end(), back_inserter(m)); if (std::distance(v.begin(), it) > 1) std::copy(v.begin(), it-1, back_inserter(n)); answer+= conv(10+*(it-1))* numberof(n)* numberof(m); } } return answer; } int main() { long liczba; cin >> liczba; long answer(1); std::vector<int> dig_r; while (liczba > 0) { dig_r.push_back(liczba - 10*(liczba/10)); liczba = liczba /10; } answer = numberof(dig_r); cout << answer << 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 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 | #include <iostream> #include <bits/stdc++.h> #include <algorithm> #include <vector> #include <cmath> using namespace std; long conv( int i) { return static_cast<long>(10 - std::abs(i-9)); } long numberof(std::vector<int> v) { long answer = 1L; if (v.size() == 0) return 1; if (v.size() == 1) return conv(v.at(0)); for (std::vector<int>::iterator it = v.begin(); it != v.end(); it++) { answer *= conv(*it); } for (std::vector<int>::iterator it = v.begin()+1; it != v.end(); it++) { if (*it ==1 && *(it-1)<9) { std::vector<int> n,m; std::copy(it+1, v.end(), back_inserter(m)); if (std::distance(v.begin(), it) > 1) std::copy(v.begin(), it-1, back_inserter(n)); answer+= conv(10+*(it-1))* numberof(n)* numberof(m); } } return answer; } int main() { long liczba; cin >> liczba; long answer(1); std::vector<int> dig_r; while (liczba > 0) { dig_r.push_back(liczba - 10*(liczba/10)); liczba = liczba /10; } answer = numberof(dig_r); cout << answer << endl; return 0; } |