HJ35
蛇形矩阵
https://www.nowcoder.com/practice/649b210ef44446e3b1cd1be6fa4cab5e
n = int(input()) pyramid = [] for i in range(1, n+1): pyramid.append([0]*i) count = 1 for i in range(n): for j in range(i+1): pyramid[i][j] = count count += 1 for i in range(n): res = "" for row in pyramid: if row: res += str(row.pop()) + " " print(res.strip())
First Create:
1
2 3
4 5 6
7 8 9 10
Then for each row, pop last item, when all rows are visited, print the result(1 3 6 10)
and do this n times