solution.cpp 782 字节
Newer Older
每日一练社区's avatar
每日一练社区 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40
#include <cstdio>

#define N 70

void f(char a[][N], int rank, int row, int col)
{
    if (rank == 1)
    {
        a[row][col] = '*';
        return;
    }

    int w = 1;
    int i;
    for (i = 0; i < rank - 1; i++)
        w *= 2;
    f(a, rank - 1, row, col + w / 2);     //(填空)处理顶上三角形
    f(a, rank - 1, row + w / 2, col);     //f(0,5,16,0)  //处理左下角
    f(a, rank - 1, row + w / 2, col + w); //f(0,5,16,16) //处理右下角
}

int main()
{
    char a[N][N];
    int i, j;
    for (i = 0; i < N; i++)
        for (j = 0; j < N; j++)
            a[i][j] = ' ';

    //f(a,6,0,0);
    f(a, 4, 0, 0);
    for (i = 0; i < N; i++)
    {
        for (j = 0; j < N; j++)
            printf("%c", a[i][j]);
        printf("\n");
    }

    return 0;
}