问题 3747 --天才小画手(完善程序)

3747: 天才小画手(完善程序)★★★

时间限制: 1 Sec  内存限制: 128 MB
提交: 17  解决: 9
[提交][状态][命题人:]

题目描述

小王对雪花曲线产生了浓厚的兴趣,他想要编一个程序来这个曲线。

#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;
}

输入

一个整数n0<= n <= 7)

输出

雪花曲线

样例输入
Copy
3
样例输出
Copy
                        __/\__                        
                        \    /                        
                  __/\__/    \__/\__                  
                  \                /                  
                  /_              _\                  
                    \            /                    
      __/\__      __/            \__      __/\__      
      \    /      \                /      \    /      
__/\__/    \__/\__/                \__/\__/    \__/\__

提示

来源

[提交][状态]