题解 | #蛇形矩阵#

蛇形矩阵

https://www.nowcoder.com/practice/649b210ef44446e3b1cd1be6fa4cab5e

#include <stdio.h>
#include <string.h>

int main() {
    int n;
    scanf("%d", &n);
    int a[101][101] = {0};
    //memset(a,0,sizeof(a));
    int i = 1, cn = n, x = 0, y = 0;
    while (cn > 0) {
        while (y >= 0 && x < n) {
            a[x][y] = i;
            x++;
            y--;
            i++;
        }
        y++;
        int t = x;
        x = y;
        y = t;
        cn--;
    }
    for (x = 0; x < n; x++) {
        for (y = 0; y < n - x; y++)
            printf("%d ", a[y][x]);
        printf("\n");
    }
    return 0;
}

全部评论

相关推荐

迷茫的大四🐶:自信一点,我认为你可以拿到50k,低于50k完全配不上你的能力,兄弟,不要被他们骗了,你可以的
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务