#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 : 111 | Submit : 174 | |
Time Limit : 1000 MS | Memory Limit : 65536 KB | |
Description | ||
Patchouli的金字塔Patchouli想要绘制一个金字塔。金字塔的图案由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 样例输出* / \ * - * * / \ * - * / \ * - * * / \ * - * / \ / * - * * / \ * - * / \ / \ * - * - * Authorpatchouli | ||
Sample Input | ||
Sample Output | ||
Source |