fork download
  1. #include<iostream>
  2. #include<bits/stdc++.h>
  3. using namespace std;
  4.  
  5. int n,ok;
  6. string a;
  7. void khoitao(){
  8. cin>>n;
  9. for(int i=1;i<=n;i++) a[i]=65;
  10. ok=0;
  11. }
  12. void in(){
  13. for(int i=1;i<=n;i++) cout<<a[i];
  14. cout<<' ';
  15. }
  16. void sinh(){
  17. int d=n;
  18. while(a[d]==66){
  19. a[d]=65;
  20. d--;
  21. }
  22. if(d==0) {
  23. ok=1;
  24. }else{
  25. a[d]=66;
  26. }
  27. }
  28. void xuli(){
  29. khoitao();
  30. while(ok==0){
  31. in();
  32. sinh();
  33. }
  34. }
  35. int main(){
  36. int t;cin>>t;
  37. while(t--){
  38. xuli();
  39. cout<<endl;
  40. }
  41. }
Success #stdin #stdout 0.01s 5472KB
stdin
2
2
4
stdout
AA AB BA BB 
AAAA AAAB AABA AABB ABAA ABAB ABBA ABBB BAAA BAAB BABA BABB BBAA BBAB BBBA BBBB