1027のプリント砂時計、C

#include <stdio.h>

int main()
{
    int i=1,n=1,a,c=0,x=0,d=0;  //c剩余,d最大行
    char b;

    scanf("%d %c",&a,&b);
    if(a>=1 && a<7)
        printf("%c\n%d",b,a-1);
    else{
        while( n <= a )
        {
            i = i + 2;
            n = n + (i*2);          
        }
        n = n - i*2;    i = i-2;    d = i;
        c = a - n;
        while( i>=1 )
        {
            x = (d - i)/2;
            while( x )  {printf(" ");     x--;}
            x = i;
            while( x )  {printf("%c",b);    x--;}
            /*x = (d - i)/2;
            while( x )  {printf(" ");     x--;}*/
            printf("\n");
            i = i-2;       
        }
        i = i+4;
        while( i<=d )
        {
            x = (d - i)/2;
            while( x )  {printf(" ");     x--;}
            x = i;
            while( x )  {printf("%c",b);    x--;}
            i = i+2;
            printf("\n");
        }
        
        printf("%d",c);
    }




    return 0;
}
公開された44元の記事 ウォンの賞賛0 ビュー879

おすすめ

転載: blog.csdn.net/weixin_43916400/article/details/104480129