Description a fractal is an object or quantity this 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 F Ollowing
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 an 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 this ' X ' is a uppercase letter. Print a line with only a single dash after each test case.
Sample Input
1
2
3
4
-1
Sample 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 by x x x x x x/x/X x x x x x x x x x x x x × x x x< C47/>x x x x x x x x × x x x x x x x
x
x x
x x x x x x x × x x x x x [x] x x x x x x x x x x x x I x x x x I x x x x x x/ X x x x x x x x x x
-
For such a recursive graph problem, simply write it out of the function to find out the rules, then find the boundary, and then write the recursion.
A bit of a tease is the title of-wrote the _,WR a lot of times ....
The use of the function pow (A, B) is the second party of a
#include <iostream>
#include <cstdio>
#include <memory.h>
#include <cmath>
using namespace std;
Char map[1000][1000];
void Paint (int n,int x,int y) {
if (n==1) {
map[x][y]= ' x ';
return;
}
int size = (int) pow (3.0,n-2);
Paint (n-1, x, y); Upper left corner
paint (n-1, x, y+size*2); upper right corner
paint (n-1, x+size, y+size); Middle
paint (n-1, x+size*2, y); Bottom left
paint (n-1, x+size*2, y+size*2);//Lower right corner
}
int main () {
int n;
while (~SCANF ("%d", &n) &&n!=-1) {
int size= (int) POW (3.0, n-1); The scale of the fractal graph with degrees N is 3^ (n-1)
memset (map, ", sizeof (map));
Paint (n, 1, 1);
for (int i=1;i<=size;i++) { //print for
(int j=1;j<=size;j++)
cout<<map[i][j];
cout<<endl;
}
cout<< '-' <<endl;
}
return 0;
}