Description: enter a matrix and print each number in clockwise order from the external direction. For example, if you enter the following matrix: 1 2 3 45 6 7 89 10 11 1213 14 15 16 the numbers 1, 2, 3, 4, 8, 12, 16, 15, 14, 13, 9, 5, 6, 7, 11, 10 are printed in sequence. input: the input may contain multiple test examples. For each test case, the first line of the input contains two integers m and n (1 <= m, n <= 1000 ): indicates that the dimension of the matrix is m rows and n columns. In the next m row, each row contains n integers, indicating the elements of the matrix. The value range of each element a is (1 <= a <= 10000 ). Output: Output a line for each test case. Each number is printed clockwise from the external direction. Each number is followed by a space. Sample input: 4 41 2 3 45 6 7 89 10 11 1213 14 15 16 sample output: 1 2 3 4 8 12 16 15 14 13 9 5 6 7 11 10 Code AC: Thought: There is no Algorithm for this question. Just control the boundary ~ [Cpp] # include <stdio. h> typedef struct mat {int num; int flag;} mat; int main () {mat ma [1000] [1000]; int I, j, m, n, dir, count; while (scanf ("% d", & m, & n )! = EOF) {for (I = 0; I <m; I ++) {for (j = 0; j <n; j ++) {scanf ("% d", & ma [I] [j]. num); ma [I] [j]. flag = 0 ;}} dir = 0; // left-bottom-right-top loop count = 0; I = 0; j = 0; while (count <n * m) {switch (dir) {case 0: if (j <n) {if (! Ma [I] [j]. flag) {printf ("% d", ma [I] [j]. num); ma [I] [j]. flag = 1; count ++; j ++;} else {j --; I ++; dir + = 1; dir % = 4 ;}} else {j --; I ++; dir + = 1; dir % = 4;} break; case 1: if (I <m) {if (! Ma [I] [j]. flag) {printf ("% d", ma [I] [j]. num); ma [I] [j]. flag = 1; count ++; I ++;} else {I --; j --; dir + = 1; dir % = 4 ;}} else {I --; j --; dir + = 1; dir % = 4;} break; case 2: if (j> = 0) {if (! Ma [I] [j]. flag) {printf ("% d", ma [I] [j]. num); ma [I] [j]. flag = 1; count ++; j --;} else {j ++; I --; dir + = 1; dir % = 4 ;}} else {j ++; I --; dir + = 1; dir % = 4;} break; case 3: if (I> = 0) {if (! Ma [I] [j]. flag) {www.2cto.com printf ("% d", ma [I] [j]. num); ma [I] [j]. flag = 1; count ++; I --;} else {I ++; j ++; dir + = 1; dir % = 4 ;}} else {I ++; j ++; dir + = 1; dir % = 4;} break ;}} printf ("\ n") ;}return 0 ;}