题解 | #蛇形矩阵#
蛇形矩阵
https://www.nowcoder.com/practice/649b210ef44446e3b1cd1be6fa4cab5e
N = int(input()) arr = [] head_1 = 1 t_1 = 0 t_2 = 2 for i in range(N): temp = [head_1] h = head_1 t_1 += 1 head_1 = head_1 + t_1 tt = t_2 t_2 = t_2 +1 for j in range(N): if i+j < N-1: temp.append(h + tt) h = h + tt tt += 1 arr.append(temp) for s in arr: for c in s: print(c, end=' ') print()