题解 | #蛇形矩阵#

蛇形矩阵

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

N = int(input())
res = [[] for _ in range(N)]
sign = -1
loc = 1
i = 1
while len(res[0]) < N:
    loc = loc + sign
    res[loc].append(str(i))
    sign = -1
    i += 1
    if loc == 0:
        sign = len(res[0])

for lst in res:
    print(" ".join(lst))

全部评论

相关推荐

09-13 17:25
亲切的00后在笔试:我也遇到了,所以我早他一步查看图片
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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