-
Title Description:
-
Enter a matrix that prints each number in a clockwise order from outward, for example, if you enter the following matrix:
1 2 3 4
5 6 7 8
9 10 11 12
13 14 15 16
The word 1,2,3,4,8,12,16,15,14,13,9,5,6,7,11,10 is printed in turn.
-
Input:
-
The input may contain multiple test samples, for each test case,
The first line of input includes two integers m and n (1<=m,n<=1000): Represents the number of dimensions of the matrix as M row n columns.
The next M-line, each row consists of n integers, representing the elements of the matrix, where each element A has a value range of (1<=a<=10000).
-
Output:
-
For each test case, output one line,
Print each number in a clockwise order from the outside, with a space behind each number.
-
Sample input:
-
4 41 2 3 45 6 7 89 10 11 1213 14 15 16
-
-
Sample output:
-
Code:
#include <cstdio>using namespacestd;intarr[1010][1010]; voidPrintmatrixincircle (intRowsintColumnsintstart) { intendx=rows-1-start; intendy=columns-1-start; for(inti=start;i<=endy;++i) printf ("%d", Arr[start][i]); if(start<EndX) { for(inti=start+1; i<=endx;++i) printf ("%d", Arr[i][endy]); } if(start<endx&&start<EndY) { for(inti=endy-1; i>=start;--i) printf ("%d", Arr[endx][i]); } if(start<endx-1&&start<EndY) { for(inti=endx-1; i>start;--i) printf ("%d", Arr[i][start]); }} intMain () {intn,m; while(SCANF ("%d%d", &n,&m)! =EOF) { for(intI=0; i<n;++i) for(intj=0; j<m;++j) scanf ("%d",&Arr[i][j]); intstart=0; intRows=N; intcolumns=m; while(rows>start*2&&columns>start*2) {printmatrixincircle (Rows,columns,start); ++start; } printf ("\ n"); } return 0;} /************************************************************** problem:1391 User:lcyvino language:c++ Re sult:accepted time:520 Ms memory:5504 kb****************************************************************/
The clockwise printing matrix of the sword point