Advertisement
chaipat

Catalan

Mar 20th, 2019
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.46 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2.  
  3. char myStr[25],ch1,ch2;
  4. int digit;
  5. int countA=0, countB=0;
  6.  
  7. void think(int index){
  8.    
  9.     if(index==2*digit) std::cout<<myStr<<"\n";
  10.     else{
  11.         myStr[index] = ch1;
  12.         countA++;
  13.        
  14.         if(countA <= digit) think(index+1);
  15.         countA--;
  16.        
  17.         myStr[index] = ch2;
  18.         countB++;
  19.         if(countA >=countB) think(index+1);
  20.         countB--;
  21.     }
  22.    
  23. }
  24.  
  25. int main(){
  26.    
  27.     std::cin>>digit;
  28.     std::cin>>ch1>>ch2;
  29.    
  30.     myStr[2*digit]=0;
  31.     think(0);
  32.    
  33.     return 0;
  34. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement