Advertisement
Guest User

Untitled

a guest
Jul 20th, 2018
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.65 KB | None | 0 0
  1. #include <iostream>
  2. #include <math.h>
  3.  
  4. using namespace std;
  5. int the_size(long long n){
  6. int counter=0;
  7. int p=n;
  8. while(p){
  9. p=p/10;
  10. counter++;
  11. }
  12. return counter-1;
  13. }
  14. int the_k(long long n,int k){
  15. int p=n;
  16. int counter=the_size(p);
  17. while(counter != k){
  18. p=p/10;counter--;
  19.  
  20. }
  21. return p%10;
  22.  
  23. }
  24. int num_ways(long long n){
  25.  
  26. if(n>9){
  27. int p=the_k(n,0)*10+the_k(n,1);
  28. if(p>9 &&p<26)
  29. 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)));
  30. else return num_ways(n-the_k(n,0)*pow(10,the_size(n)));
  31. }
  32. return 1;
  33. }
  34.  
  35.  
  36.  
  37. int main(){
  38. cout<<num_ways(9919);
  39. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement