#include <iostream>
#include <math.h>
using namespace std;
#define MAXN 730
void func(char frac[][730],int startX,int startY,int n){
if(n == 1)frac[startX][startY] = 'X';
else{
int L0 = (int)pow(3,n - 2);
//(startX,startY)是最左上角那个
func(frac,startX,startY,n - 1);
func(frac,startX + L0,startY + L0,n - 1);
func(frac,startX + 2*L0,startY,n - 1);
func(frac,startX,startY + 2*L0,n - 1);
func(frac,startX + 2*L0,startY + 2*L0,n - 1);
}
}
int main()
{
int n;
int count = 0;
while(cin >> n){
if(n == -1)break;
if(count != 0)cout << "-" << endl;
count ++;
int measure = (int)pow(3,n - 1);
char frac[MAXN][MAXN];
func(frac,0,0,n);
for(int i = 0;i < measure;i ++){
int max = 0;
for(int j = 0;j < measure;j ++){
if(frac[i][j] == 'X'){
max = j;
}
else frac[i][j] = ' ';
}
frac[i][max + 1] = '\0';
}
for(int i = 0;i < measure;i ++){
cout << frac[i] << endl;
}
}
return 0;
}
1246: A006 分形(Fractal)
最新推荐文章于 2024-08-24 14:08:21 发布