Guest User

Untitled

a guest
Jan 3rd, 2020
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.93 KB | None | 0 0
  1. #include<iostream>
  2. using namespace std;
  3.  
  4. void count(char * in, int n, int i, char ch, int &c){
  5.     if(i == n){
  6.         in[i] = '\0';
  7.         return;
  8.     }
  9.     if(i != 0 ){
  10.          if( in[i-1] == in[i] && in[i-1] == 'b' && in[i] == 'b'){
  11.             return;
  12.             //why not this condition is being executed because of it recursion is not stopping at desired place
  13.         }
  14.     }
  15.      
  16.    
  17.     in[i] = ch;
  18.     if(i == n -1){
  19.          c++;
  20.           cout<<c<<endl;
  21.           cout<<in<<" "<<i-1<<" "<<i<<endl;
  22.     }
  23.        
  24.     count(in, n, i+1, 'a', c);
  25.     count(in, n, i+1, 'b', c);
  26.     in[i] = '\0';
  27.     return;
  28. }
  29.  
  30. int main(){
  31.     int t;
  32.     cin>>t;
  33.     while(t--){
  34.         int n;
  35.         cin>>n;
  36.         char *in = new char[n+1];
  37.         int c = 0;
  38.         count(in, n, 0, 'a', c);
  39.       //  cout<<c<<endl;
  40.         count(in, n, 0, 'b', c);
  41.         cout<<c<<endl;
  42.    
  43.     }
  44.     return 0;
  45.    
  46. }
Add Comment
Please, Sign In to add comment