#include <iostream> #include <cstdio> #include <cmath> using namespace std; const int maxn = 10000; char map[maxn][maxn]; //n :度数 void prepare(int n, int x, int y) { if (n == 1) {//递归边界 map[x][y] = 'X'; return; } //以下是搜索范围,共5各组成部分 int size = (int)pow(3.0,n-2);//n-2 :规模 prepare(n - 1, x, y);//左上角 prepare(n - 1, x , y + size * 2);//右上角 prepare(n - 1, x + size, y + size);//中间 prepare(n - 1, x + size * 2, y);//左下角 prepare(n - 1, x + size * 2, y + size * 2);//右下角 } int main() { int n; while (scanf("%d", &n) != EOF, n != -1) { int i, j; int size = (int) pow(3.0, n - 1);//度为n的分形图的规模是3^(n-1) //他是一个度为n,大小为size*size的图 //初始化 for (i = 1; i <= size; ++i) { for (j = 1; j <= size; ++j) { map[i][j] = ' '; } } prepare(n, 1, 1); for (i = 1; i <= size; ++i) {//打印 printf("%s\n", map[i]+1); } printf("-\n"); } return 0; }