// apb.cpp : Defines the entry point for the console application. // #include <iostream> #include <string> #include <vector> using namespace std; int main(int argc, char* argv[]) { vector<int> num_of_sum(19, 0); for(int i=0; i<=9; i++) for(int j=0; j<=9; j++) num_of_sum[i+j]++; string s; cin >> s; vector<long long> res(s.size()+1); res[0] = 1LL; for(size_t i=0; i<s.size(); i++) { if(i>0 && s[i-1]=='1' && s[i] <='8') { res[i+1] += res[i-1] * num_of_sum[10 + s[i]-'0']; } res[i+1] += res[i] * num_of_sum[s[i]-'0']; } cout << res.back() << 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 | // apb.cpp : Defines the entry point for the console application. // #include <iostream> #include <string> #include <vector> using namespace std; int main(int argc, char* argv[]) { vector<int> num_of_sum(19, 0); for(int i=0; i<=9; i++) for(int j=0; j<=9; j++) num_of_sum[i+j]++; string s; cin >> s; vector<long long> res(s.size()+1); res[0] = 1LL; for(size_t i=0; i<s.size(); i++) { if(i>0 && s[i-1]=='1' && s[i] <='8') { res[i+1] += res[i-1] * num_of_sum[10 + s[i]-'0']; } res[i+1] += res[i] * num_of_sum[s[i]-'0']; } cout << res.back() << endl; return 0; } |