#include <iostream> #include <string> using namespace std; int main(){ long long unsigned int n, result, prev,tmp; cin >> n; string s = to_string(n); prev = 1; result = s[s.size()-1] - '0' + 1; for(int i=s.size() - 2; i >=0; i-- ){ tmp = result * (s[i] - '0' + 1); if( s[i] == '1' && s[i+1] < '9' ){ tmp += prev * (9- s[i+1] + '0'); } prev = result; result = tmp; } cout << result; 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 | #include <iostream> #include <string> using namespace std; int main(){ long long unsigned int n, result, prev,tmp; cin >> n; string s = to_string(n); prev = 1; result = s[s.size()-1] - '0' + 1; for(int i=s.size() - 2; i >=0; i-- ){ tmp = result * (s[i] - '0' + 1); if( s[i] == '1' && s[i+1] < '9' ){ tmp += prev * (9- s[i+1] + '0'); } prev = result; result = tmp; } cout << result; return 0; } |