#include #include #include #include using namespace std; ifstream in("fractal.in"); void output(unsigned n, char * matrix) { for(unsigned y = 0; y < n/2; y++) { for(unsigned x = 0; x < 2*n; x++) { char h = matrix[y*2*n + x]; matrix[y*2*n + x] = matrix[(n-y-1)*2*n + x]; matrix[(n-y-1)*2*n + x] = h; } } for(unsigned y = 0; y < n; y++) { unsigned maxx = 2*n-1; while(matrix[y*2*n + maxx] == 0) maxx--; maxx++; for(unsigned x = 0; x < maxx; x++) { char code = matrix[y*2*n + x]; if(code == 1) cout << " /"; else if(code == 2) if(x+1 == maxx) cout << "\\"; else cout << "\\ "; else cout << " "; } cout << endl; for(unsigned x = 0; x < maxx; x++) { char code = matrix[y*2*n + x]; if(code == 1) cout << "/_"; else if(code == 2) cout << "_\\"; else cout << " "; } cout << endl; } } unsigned power2(unsigned e) { return 1 << e; } void recurse(unsigned n, char * matrix, unsigned l) { if(l == n) return; for(unsigned y = 0; y < l; y++) for(unsigned x = 0; x < 2*l; x++) { matrix[2*l + y*2*n + x] = matrix[y*2*n + x]; matrix[l + l*2*n + y*2*n + x] = matrix[y*2*n + x]; } recurse(n, matrix, 2*l); } int main() { int n; while((in >> n) && n != 0) { unsigned m = power2(n-1); char * matrix = new char[2*m*m]; memset(matrix, 0, 2*m*m); matrix[0] = 1; matrix[1] = 2; recurse(m, matrix, 1); output(m, matrix); cout << endl; delete [] matrix; } return 0; }