Poj 1941 The Sierpinski Fractal recursion, pojsierpinski
// Poj 1941 // sep9 # include <iostream> using namespace std; const int maxW = 2048; const int maxH = 1024; int pow2 [32]; char g [maxH + 10] [maxW + 10]; void print (int x, int y, int n) {if (n = 1) {g [x] [y + 1] = '/'; g [x] [y + 2] = '\\'; g [x + 1] [y] = '/'; g [x + 1] [y + 1] = '_'; g [x + 1] [y + 2] = '_'; g [x + 1] [y + 3] = '\'; return;} print (x, y + pow2 [n-1], n-1); print (x + pow2 [n-1], y, n-1); print (x + pow2 [n-1], y + pow2 [n], n-1); return;} int main () {pow2 [0] = 1; for (int I = 1; I <30; ++ I) pow2 [I] = pow2 [I-1] * 2; int n; while (scanf ("% d", & n) = 1 & n) {int H = pow2 [n]; int W = pow2 [n + 1]; memset (g, '', sizeof (g); print (0, 0, n ); for (int I = 0; I <H; ++ I) {for (int j = 0; j <W; ++ j) printf ("% c ", g [I] [j]); printf ("\ n");} puts ("");} return 0 ;}
Copyright Disclaimer: This article is an original article by the blogger and cannot be reproduced without the permission of the blogger.