6 条题解

  • 1
    @ 2025-11-24 18:29:18
    #include<stdio.h>
    #include <math.h>
    #include <stdlib.h>
    int main(){
        int n,cnt=0,temp;
        scanf("%d",&n);
        for(int j=1;j<=n/2+1;j++){
            temp=j;
            for(int i=1;i<=n;i++){
                if(j*2-1==cnt||temp<=n/2){printf(" ");temp++;}
                else {printf("*");cnt++;}
            }
            printf("\n");cnt=0;
        }
        for(int j=n/2;j>=1;j--){
            temp=j;
            for(int i=1;i<=n;i++){
                if(j*2-1==cnt||temp<=n/2){printf(" ");temp++;}
                else {printf("*");cnt++;}
            }
            printf("\n");cnt=0;
        }
        return 0;
    }
    
    • @ 2025-11-24 18:32:54

      用上下半段循环的思路,上半段到 n/2+1、下半段从 n/2 递减,做了一个小时终于做出来了,需要就拿去借鉴吧,思路还是很简单的明确

    • @ 2025-11-24 18:34:14

      哦对了,可以把后俩头文件删了,之前我用绝对值函数做不对加上的

信息

ID
65
时间
1000ms
内存
128MiB
难度
5
标签
(无)
递交数
1998
已通过
729
上传者