很蠢的递归:
#include<bits/stdc++.h>
using namespace std;
const int N=1000;
int n;
char c[N][N];
void GA(int n,int x,int y){
if(n==1){
c[x][y]='x';
return;
}
GA(n-1,x,y);
GA(n-1,x,y+2*(pow(3,n-2)));
GA(n-1,x+pow(3,n-2),y+pow(3,n-2));
GA(n-1,x+2*(pow(3,n-2)),y);
GA(n-1,x+2*(pow(3,n-2)),y+2*(pow(3,n-2)));
}
int main(){
cin>>n;
while(n!=-1){
GA(n,1,1);
for(int i=1;i<=3*pow(3,(n-2));i++){
for(int j=1;j<=3*pow(3,n-2);j++){
if(c[i][j]!=0)cout<<c[i][j];
else cout<<" ";
}
cout<<endl;
}
cout<<"-"<<endl;
cin>>n;
}
return 0;
}
改出必关
改出必关
改出必关
改出必关
改出必关
改出必关