Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <math.h>
- using namespace std;
- int the_size(long long n){
- int counter=0;
- int p=n;
- while(p){
- p=p/10;
- counter++;
- }
- return counter-1;
- }
- int the_k(long long n,int k){
- int p=n;
- int counter=the_size(p);
- while(counter != k){
- p=p/10;counter--;
- }
- return p%10;
- }
- int num_ways(long long n){
- if(n>9){
- int p=the_k(n,0)*10+the_k(n,1);
- if(p>9 &&p<26)
- return num_ways(n-the_k(n,0)*pow(10,the_size(n))-the_k(n,1)*pow(10,the_size(n)-1))+num_ways(n-the_k(n,0)*pow(10,the_size(n)));
- else return num_ways(n-the_k(n,0)*pow(10,the_size(n)));
- }
- return 1;
- }
- int main(){
- cout<<num_ways(9919);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement