#include "bits/stdc++.h" using namespace std; using ll = long long; int main() { unordered_map <int, int> M; for(int d1=0; d1<10; d1++) { for(int d2=0; d2<10; d2++) { M[d1+d2]++; } } string x; cin >> x; int n = (int)x.size(); function<ll(int)> go = [&](int ix) { if(ix == n) return 1LL; ll res = 0; if(ix + 1 <= n) res += go(ix+1) * M[stoi(x.substr(ix, 1))]; if(x[ix] != '0' and ix + 2 <= n) res += go(ix+2) * M[stoi(x.substr(ix, 2))]; return res; }; cout << go(0) << "\n"; }
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 | #include "bits/stdc++.h" using namespace std; using ll = long long; int main() { unordered_map <int, int> M; for(int d1=0; d1<10; d1++) { for(int d2=0; d2<10; d2++) { M[d1+d2]++; } } string x; cin >> x; int n = (int)x.size(); function<ll(int)> go = [&](int ix) { if(ix == n) return 1LL; ll res = 0; if(ix + 1 <= n) res += go(ix+1) * M[stoi(x.substr(ix, 1))]; if(x[ix] != '0' and ix + 2 <= n) res += go(ix+2) * M[stoi(x.substr(ix, 2))]; return res; }; cout << go(0) << "\n"; } |