小王对雪花曲线产生了浓厚的兴趣,他想要编一个程序来这个曲线。
#include <stdio.h>
#include <string.h>
char *image;
int x, y, w, h;
void Put(int i, int j, char c)
{
char *p = &image[j * w + i];
if (*p == ' ' || *p == '_')
*p = c;
}
void KochCurve(int n, int dir)
{
if (n == 0)
switch (dir % 6)
{
case 0:
Put(x++, y, '_');
Put(x++, y, '_');
break;
case 1:
Put(x++, y--, '/');
break;
case 2:
Put(--x, y--, '\\');
break;
case 3:
Put(--x, y, '_');
Put(--x, y, '_');
break;
case 4:
Put(--x, ++y, '/');
break;
case 5:
Put(x++, ++y, '\\');
break;
}
else
{
KochCurve(n - 1, dir);
KochCurve(n - 1, __(1)__);
KochCurve(n - 1, dir + 5);
KochCurve(n - 1, __(2)__);
}
}
int pow(int n)
{
int r = 1;
while (n-- > 0)
{
r *= 3;
}
return r;
}
int main()
{
int n;
scanf("%d", &n);
h = __(3)__;
w = 6 * h;
image = new char[w * h];
memset(image, ' ', w * h);
x = 0;
y = h - 1;
KochCurve(_____(4)______);
for (int j = 0; j < h; j++)
{
for (int i = 0; i < w; i++)
putchar(_____(5)_______);
putchar('\n');
}
delete[] image;
}