题解 | #蛇形矩阵#
蛇形矩阵
https://www.nowcoder.com/practice/649b210ef44446e3b1cd1be6fa4cab5e
# 看成 00, 10, 01, 20, 11, 20, 30, 21, 12, 03每一斜对角的和都是行数
n = int(input())
mat = [[0] * (n - i) for i in range(n)]
# print(mat)
j = 0
for i in range(n):
a = 0
while (i - a) >= 0:
# print(i - a, a, j)
mat[i - a][a] = j + 1
a += 1
j += 1
for i in range(n):
print(" ".join([str(mat[i][j]) for j in range(len(mat[i]))]))