//3_4_1: Fractal 分形打印X POJ2083 ZOJ2423
#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;
char map[730][730];
void print(int n,int x,int y)
{
int i,m = 1;
if(n == 1)
{
map[x][y] = 'X';
return;
}
for(i = 2;i < n;i ++) m *= 3;
print(n - 1,x,y);
print(n - 1,x,y + 2 * m);
print(n - 1,x + m,y + m);
print(n - 1,x + 2 * m,y);
print(n - 1,x + 2 * m,y + 2 * m);
}
int main()
{
int i,j,n,mat;
while(scanf("%d",&n), n != -1)
{
memset(map,' ',sizeof(map));
mat = 1;
for(i = 1;i < n;i ++) mat *= 3;
print(n,0,0);
for(i = 0;i < mat;i ++)
{
for(j = 0;j < mat;j ++) printf("%c",map[i][j]);
printf("\n");
}
printf("-\n");
}
return 0;
}
/*测试结果:通过POJ2083检测,ZOJ2423无法通过,需要修改代码
1
X
-
2
X X
X
X X
-
3
X X X X
X X
X X X X
X X
X
X X
X X X X
X X
X X X X
-
4
X X X X X X X X
X X X X
X X X X X X X X
X X X X
X X
X X X X
X X X X X X X X
X X X X
X X X X X X X X
X X X X
X X
X X X X
X X
X
X X
X X X X
X X
X X X X
X X X X X X X X
X X X X
X X X X X X X X
X X X X
X X
X X X X
X X X X X X X X
X X X X
X X X X X X X X
-
-1
请按任意键继续. . .
*/
POJ2083 ZOJ2423 Fractal
最新推荐文章于 2020-05-15 16:28:36 发布