解题思路:
注意事项:
参考代码:
n = int(input())
a = 1
n = 2*n -1
l = [[0 for j in range(n)] for i in range(n)]
row = 0
col = n//2
l[0][col] = 1
while a < n*n:
a += 1
if 0 <= (row-1) <= n-1 and 0<= (col+1) <= n-1 and l[row-1][col+1] == 0:
row -= 1
col += 1
l[row][col] = a
elif 0 <= (row-1) <= n-1 and 0<= (col+1) <= n-1 and l[row-1][col+1] != 0:
row += 1
l[row][col] = a
elif row == 0 and col == n-1:
row += 1
l[row][col] = a
elif row == 0:
row = n-1
col += 1
l[row][col] = a
elif col == n-1:
row -= 1
col = 0
l[row][col] = a
for i in l:
print(*i)
0.0分
1 人评分
C语言训练-斐波纳契数列 (C语言代码)浏览:1271 |
C语言程序设计教程(第三版)课后习题7.3 (C语言代码)浏览:643 |
C语言程序设计教程(第三版)课后习题6.3 (C语言代码)浏览:553 |
C语言程序设计教程(第三版)课后习题5.4 (C语言代码)浏览:552 |
C语言程序设计教程(第三版)课后习题6.5 (C++代码)浏览:487 |
1009题解浏览:802 |
C语言程序设计教程(第三版)课后习题5.7 (C语言代码)浏览:569 |
星期判断机 (C语言代码)浏览:892 |
C语言程序设计教程(第三版)课后习题1.5 (C语言代码)浏览:438 |
sizeof的大作用 (C语言代码)浏览:1138 |