Basic exercise retrieval time limit: 1.0 s memory limit: 512.0MB Problem description: The number of retrieval is the number of edges in the matrix. If there are countless edges in the current direction, turn left 90 degrees. At the beginning, it is in the upper left corner of the matrix and the direction is down. In the input format, the first line is two positive integers (m, n) not greater than 200, indicating the rows and columns of the matrix. N integers in each row in the next m line indicate this matrix. The output format outputs only one row, with a total of mn numbers. The result is the number of input matrix return operations. Separate the numbers with one space. Do not add any extra space at the end of the line. Example input 3 3
1 2 3
4 5 6
7 8 9 sample output 1 4 7 8 9 6 3 2 5 sample input 3 2
1 2
3 4
5 6 sample output 1 3 5 6 4 2
Import java. util. extends; public class Main {public static void main (String [] args) {extends = new loads (System. in); while (partial. hasNext () {int m = seconds. nextInt (); int n = bytes. nextInt (); int [] [] flag = new int [m] [n]; // mark the path int [] [] nums = new int [m] [n]; // record data for (int I = 0; I <m; I ++) {for (int j = 0; j <n; j ++) {nums [I] [j] = numeric. nextInt () ;}} int count = m * n; int I = 0, j = 0; While (count> 0) {while (I <m & flag [I] [j] = 0) {System. out. print (nums [I] [j]); System. out. print (-- count = 0? "\ R \ n": ""); flag [I] [j] = 1; I ++;} I --; j ++; while (j <n & flag [I] [j] = 0) {System. out. print (nums [I] [j] + ""); System. out. print (-- count = 0? "\ R \ n": ""); flag [I] [j] = 1; j ++;} j --; I --; while (I>-1 & flag [I] [j] = 0) {System. out. print (nums [I] [j] + ""); System. out. print (-- count = 0? "\ R \ n": ""); flag [I] [j] = 1; I --;} I ++; j --; while (j>-1 & flag [I] [j] = 0) {System. out. print (nums [I] [j] + ""); System. out. print (-- count = 0? "\ R \ n": ""); flag [I] [j] = 1; j --;} j ++; I ++ ;}}}}