蛇形矩阵
蛇形矩阵
http://www.nowcoder.com/questionTerminal/649b210ef44446e3b1cd1be6fa4cab5e
每次增加都是在原有的基础上增加。
while True: try: size = int(input()) base = [[0 for i in range(size)] for j in range(size)] count = 1 for index in range(size): x = index for i in range(x, -1, -1): base[i][x-i] = count count += 1 res = '' for i in base: for j in i: if j != 0: res = res + str(j) + ' ' print(res.strip()) res = '' except Exception as e: print(e) break
5 1 3 6 10 15 2 5 9 14 4 8 13 7 12 11