• sss


    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;
    	}
    }
    
  • 相关阅读:
    lookup:ID列
    分享几篇文章
    怎样无限制使用smartgit ?
    C++ Win32控制台应用程序捕捉关闭事件
    mt4 在K线上 放文字
    变色指标
    用windows 打包 证书
    监管fca asic nfa 啥啥啥
    sublime 3 build 3126 code ,压缩包在我的360企业云盘里,搜sublime
    个人作业收官——软件工程实践总结
  • 原文地址:https://www.cnblogs.com/lqhsr/p/11265623.html
Copyright © 2020-2023  润新知