import java.util.*;
public class Main {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int m, n;
m = in.nextInt();
n = in.nextInt();
int[][] a = new int[m][n];
for (int i = 0; i < m; i++) {
for (int j = 0; j < n; j++) {
a[i][j] = in.nextInt();
}
}
int title = 0, x = -1, y = 0;
while(title < m*n){
while(x+1 < m && a[x+1][y] != -1){
System.out.print(a[++x][y]+" ");
a[x][y] = -1;
++title;
}
while(y+1 < n && a[x][y+1] != -1){
System.out.print(a[x][++y]+" ");
a[x][y] = -1;
++title;
}
while(x-1 >= 0 && a[x-1][y] != -1){
System.out.print(a[--x][y]+" ");
a[x][y] = -1;
++title;
}
while(y-1 >= 0 && a[x][y-1] != -1){
System.out.print(a[x][--y]+" ");
a[x][y] = -1;
++title;
}
}
}
}
回形取数。
最新推荐文章于 2024-10-01 23:05:47 发布