POJ-2083 Fractal-X星阵图

Description

A fractal is an object or quantity that displays self-similarity, in a somewhat technical sense, on all scales. The object need not

exhibit exactly the same structure at all scales, but the same "type" of structures must appear on all scales.

A box fractal is defined as below :

A box fractal of degree 1 is simply

X 

A box fractal of degree 2 is

X  X 

  X 

X  X 

If using B(n - 1) to represent the box fractal of degree n - 1, then a box fractal of degree n is defined recursively as following

B(n - 1)        B(n - 1)

        B(n - 1)

B(n - 1)        B(n - 1)

Your task is to draw a box fractal of degree n.

Input

The input consists of several test cases. Each line of the input contains a positive integer n which is no greater than 7.

The last line of input is a negative integer −1 indicating the end of input.

Output

For each test case, output the box fractal using the 'X' notation. Please notice that 'X' is an uppercase letter. Print a line

with only a single dash after each test case.

Sample Input

1

2

3

4

-1

Examples

Input

3

2 3 2

2

3 2

2 3

Output

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 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
-

Analysis

一句话题意:打印图形

其实就是把删一个图形在右上、左下、右下分别复制粘贴一遍就OK了

然而我居然习惯输出空格导致WA了3发。。。

代码

真的很水啦。。。

#include<iostream>
#include<algorithm>
#include<cstdlib>
#include<cstdio>
#include<cstring>
using namespace std;
int n,cnt[100];
char co[1000][1000];
void copy(int k,int x,int y){
	for(int j=1;j<=cnt[k-1];j++){
		for(int l=cnt[k-1]*2+1;l<=cnt[k];l++){//右上 
			co[j][l]=co[j][l-cnt[k-1]*2];
		}
	}
	for(int j=cnt[k-1]+1;j<=cnt[k-1]*2;j++){//中间 
		for(int l=cnt[k-1]+1;l<=cnt[k-1]*2;l++){
			co[j][l]=co[j-cnt[k-1]][l-cnt[k-1]];
		}
	}
	for(int j=cnt[k-1]*2+1;j<=cnt[k];j++){//左下 
		for(int l=1;l<=cnt[k-1];l++){
			co[j][l]=co[j-cnt[k-1]*2][l];
		}
	}
	for(int j=cnt[k-1]*2+1;j<=cnt[k];j++){//右下 
		for(int l=cnt[k-1]*2+1;l<=cnt[k];l++){
			co[j][l]=co[j-cnt[k-1]*2][l-cnt[k-1]*2];
		}
	}
}
int main(){
	cnt[0]=cnt[1]=1;
	for(int i=2;i<=10;i++)cnt[i]=cnt[i-1]*3;
	while(cin>>n){
		memset(co,' ',sizeof(co));
		if(n==-1)return 0;
		co[1][1]='X';
		for(int i=2;i<=n;i++){
			copy(i,cnt[i],cnt[i]);
		}
		for(int i=1;i<=cnt[n];i++){
			for(int j=1;j<=cnt[n];j++){
				cout<<co[i][j];
			}
			cout<<endl;
		}
		cout<<"-"<<endl;
	}
}
posted @ 2019-07-29 18:18  lqhsr  阅读(268)  评论(0编辑  收藏  举报