The sample input
5
Sample output
11 July 4 2 1
16 12 August 5 3
20 17 13 9 6
23 21 18 14 10
25 24 22 19 15
CodePudding user response:
def FormMatrix (num) :
CurNum maxNum=1, num * * 2
LstData=https://bbs.csdn.net/topics/[[] for I in range (num)]
F_initCol f_initRow, f_curRow, f_curCol=0, num - 1, num 1
While curNum & lt;=maxNum:
LstData [f_curRow]. Append (curNum)
F_curRow +=1
F_curCol +=1
If f_curRow & lt; Num and f_curCol==num:
F_initCol -=1
F_curCol=f_initCol
F_curRow=f_initRow=0
Elif f_curRow==num and f_curCol==num:
F_curCol=f_initCol=0
F_curRow=f_initRow=1
Elif f_curRow==num and f_curCol & lt; Num:
F_curCol=f_initCol=0
F_initRow +=1
F_curRow=f_initRow
CurNum +=1
Return lstData
L=FormMatrix (5)
Print ([I] [: : - 1 for I in l])