include <stdio.h>
void Show(int num,char symbol); //显示字符
int Charge(int n);//判断打印行数
int main()
{
int number,n,i,m=0;
char x;
scanf("%d %c",&number,&x);
n=Charge(number);
for(i=1;i<=n/2+1;i++)
{
Show(i-1,' ') ;
Show(1+2*(1+n/2-i),x);
m += 1+2*(1+n/2-i);
putchar('\n');
}
for(i=1;i<=n/2;i++)
{
Show(n/2-i,' ');
Show(1+2*i,x);
m += 1+2*i;
putchar('\n');
}
printf("%d",number-m);
return 0;
}
void Show(int num,char symbol)
{
int i;
for(i=1;i<=num;i++)
{
printf("%c",symbol);
}
}
int Charge(int n)
{
int i=1,m,k;
m=n-1;
k=3;
for(;m>=2*k;k += 2,i += 2)
{
m -= 2*k;
}
return i;
}
PTA groups Programming Ladder Race - Practice set L1-002 print hourglass
Guess you like
Origin blog.csdn.net/qq_44410340/article/details/91038556
Recommended
Ranking