Run ID:109835

提交时间:2025-02-12 14:23:26

n = int(input()) # 小学生数学视角 ; n = int(input()) 初中高中学生数学视角 # a = [ [0]*n for x in range(n) ] a = [ [0 for y in range(n)] for x in range(n) ] num = 1 x,y = 0 , n-1 while num<= n**2: #A1 Pattern while 0<=x<=n-1 and 0<=y<=n-1 and a[x][y]==0: a[x][y] = num x = x +1 num +=1 #jump to the up-left x = x -1 y = y -1 # A2 Pattern while 0 <= x <= n - 1 and 0 <= y <= n - 1 and a[x][y] == 0: a[x][y] = num y = y - 1 num += 1 # jump to the up-right x = x - 1 y = y + 1 # A3 Pattern while 0 <= x <= n - 1 and 0 <= y <= n - 1 and a[x][y] == 0: a[x][y] = num x = x - 1 num += 1 # jump to the below-right x = x + 1 y = y + 1 # A4 Pattern while 0 <= x <= n - 1 and 0 <= y <= n - 1 and a[x][y] == 0: a[x][y] = num y = y + 1 num += 1 # jump to the below-left x = x + 1 y = y -1 for row in a: print( *row)