Run ID 作者 问题 语言 测评结果 Time Memory 代码长度 提交时间
109631 胡海峰老师 方阵填数 Python3 Accepted 39 MS 3848 KB 705 2025-02-10 09:16:02

Tests(3/3):


Code:

n = int(input()) a = [[0]*n for x in range(n)] i=1 x,y=0,n-1 while i<=n**2: while 0<=x<=n-1 and 0<=y<=n-1 and a[x][y]==0: a[x][y] = i x+=1 i+=1 x-=1;y-=1 while 0<=x<=n-1 and 0<=y<=n-1 and a[x][y]==0: a[x][y] = i y-=1 i+=1 x -= 1; y += 1 while 0 <= x <= n - 1 and 0 <= y <= n - 1 and a[x][y] == 0: a[x][y] = i x -= 1 i += 1 x += 1; y += 1 while 0 <= x <= n - 1 and 0 <= y <= n - 1 and a[x][y] == 0: a[x][y] = i y += 1 i += 1 x += 1; y -= 1 for row in a: for ele in row: print(ele,end=" ") print()