标签:new div can com stat code void str for
import java.util.*; public class Main { static int dr[]={0,1,0,-1};///向左加,向右减 static int dc[]={1,0,-1,0};///向下加,向上减 static int arr[][]; static int n,m; public static void main(String [] args) { Scanner sc = new Scanner(System.in); n = sc.nextInt(); m = sc.nextInt(); arr = new int[n + 10][m + 10]; for (int i = 0; i < n; i++) for (int j = 0; j < m; j++) arr[i][j] = sc.nextInt(); System.out.print(arr[0][0]); arr[0][0]=-1; int t=0; int r=0; int c=0; int j=0; while(++t<n*m){ while(true){ int x = r+dr[j]; int y = c+dc[j]; if(panduan(x,y)&&arr[x][y]!=-1){ System.out.print(" "+arr[x][y]); arr[x][y]=-1; r=x; c=y; break; } j++; if(j>=4) j-=4; } } } static boolean panduan(int r,int c){ return r>=0 && r<n && c>=0 &&c<m; } }
标签:new div can com stat code void str for
原文地址:https://www.cnblogs.com/wszhu/p/12804895.html