提交时间:2024-08-21 13:30:23

运行 ID: 180440

#include <iostream> using namespace std; const int N = 1e3; int B[N][N]; void dfs(int n){ if(n == 1){ B[0][0] = 1; return; } dfs(n - 1); int len_n_1 = 1; for(int i = 1;i <= n - 2;i++) len_n_1 *= 3; int dx[4] = {0,1,2,2,},dy[5] = {2,1,0,2}; for(int i = 0;i < 4;i++) for(int j = 0;j < len_n_1;j++) for(int k = 0;k < len_n_1;k++) B[dx[i] * len_n_1 + j][dy[i] * len_n_1 + k] = B[j][k]; return; } int main(){ dfs(7); int n; while(cin >> n && n != -1){ int len_n = 1; for(int i = 1;i < n;i++) len_n *= 3; for(int i = 0;i < len_n;i++){ for(int j = 0;j < len_n;j++) if(B[i][j] == 1) cout << 'X'; else cout << ' '; cout << endl; } cout << '-' << endl; } return 0; }