xtu Patchouli的金字塔 1397

#include <stdio.h>
int space;
void printspace(void)
{
    int times = space;
    while (times--)
    {
        printf(" ");
    }
    space--;
}
void printx(int times)
{
    printf("*");
    while (times--)
    {
        printf(" - *");
    }
    printf("\n");
}
void printg(int time)
{
    printf("/");
    int temp = 1;
    while (time--)
    {
        if (temp % 2 != 0)
        {
            printf(" \\");
        }
        else
        {
            printf(" /");
        }
        temp++;
    }
    printf("\n");
}
int turnline(int a)
{
    int i = 1;
    while (1)
    {
        if (a <= i * i)
        {
            break;
        }
        i++;
    }
    return i;
}
int main()
{

    int t, input, countline, counts;
    scanf("%d", &t);
    while (t--)
    {
        scanf("%d", &input);
        countline = turnline(input);
        space = 2 * countline;
        printspace();
        printf("*\n");
        for (int i = 1; i <= countline; i++)
        {
            if (input >= i * i)
                counts = 2 * i - 1;
            else
                counts = input - (i - 1) * (i - 1);
            printspace();
            printg(counts);
            printspace();
            printx((counts+1)/2);
        }
    }
}

Patchouli的金字塔

Submit Code ] [ Top 20 Runs ] [ Runs Status ]
Acceteped : 111Submit : 174
Time Limit : 1000 MSMemory Limit : 65536 KB

Description

Patchouli的金字塔

Patchouli想要绘制一个金字塔。金字塔的图案由n个正三角形和倒三角形堆叠而成,具体的绘制方法如下:

  • 每个三角形由*/\-组成,分别代表三角形的顶点和三条边。

  • 第一行只包含一个正三角形,其余各行的三角形按照”正三角形,倒三角形,正三角形,倒三角形,…… “的顺序紧致排列。

  • 除最后一行外,每一行的三角形比上一行多2个。一共输出n个三角形。

例如,n=1时,图案如下:

  *
 / \
* - *

n=2时,图案如下:

    *
   / \
  * - *
 / \
* - *

n=3时,图案如下:

    *
   / \
  * - *
 / \ /
* - *

n=7时,图案如下:

      *
     / \
    * - *
   / \ / \
  * - * - *
 / \ / \
* - * - *

Patchouli想知道n个三角形组成的金字塔的图案是怎样的?

输入

第一行包含一个正整数T(1≤T≤100),表示样例的个数。 接下来的T行,每行包含一个正整数n(1≤n≤100),表示金字塔中的三角形的个数。

输出

对于每个样例输出对应的图案。每行的行末不包含多余的空格。

样例输入

4
1
2
3
4

样例输出

  *
 / \
* - *
    *
   / \
  * - *
 / \
* - *
    *
   / \
  * - *
 / \ /
* - *
    *
   / \
  * - *
 / \ / \
* - * - *

Author

patchouli

Sample Input

 

Sample Output

 

Source

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值