记录:蓝桥杯python 基础练习 回形取数
m,n = map(int,input().split())
lista = [input().split() for i in range(m)]
sign = 0
x,y = 0,0
print(lista[0][0],end=' ')
lista[0][0] = 0
while sign < m*n:
while x+1<m and lista[x+1][y]:
x=x+1
print(lista[x][y],end=' ')
lista[x][y] = 0
while y+1<n and lista[x][y+1]:
y=y+1
print(lista[x][y],end=' ')
lista[x][y] = 0
while x-1>=0 and lista[x-1][y]:
x=x-1
print(lista[x][y],end=' ')
lista[x][y] = 0
while y-1>=0 and lista[x][y-1]:
y=y-1
print(lista[x][y],end=' ')
lista[x][y] = 0
sign = sign+1