提交时间:2024-08-20 21:28:11
运行 ID: 173553
#include <iostream> #include <cstring> using namespace std; char ans[2200][2200]; void solve(int n,int len,int x,int y) { if (n==1) { ans[x][y]='X'; return; } int tmp=len/3; solve(n-1,tmp,x,y); solve(n-1,tmp,x,y+tmp+tmp); solve(n-1,tmp,x+tmp,y+tmp); solve(n-1,tmp,x+tmp+tmp,y); solve(n-1,tmp,x+tmp*2,y+tmp*2); } int main() { int n,m; while (true) { scanf("%d",&n); if (n==-1) break; m=1; for (int i=2;i<=n;++i) m*=3; // memset(ans,' ',sizeof(ans)); solve(n,m,1,1); for (int i=1;i<=m;++i) { for (int j=1;j<=m;++j) printf("%c",ans[i][j]); printf("\n"); } printf("-\n"); } return 0; }