Total time limit: 1000ms memory limit: 65536kB description
Given an integer array of row row col columns, requires starting from the array[0][0] element, and pressing the back shape to traverse the entire array in a clockwise order from outward. As shown in the figure:
The first line of the input input has two integers, followed by row and Col.
The remaining row rows, each containing a col integer, form a two-dimensional array of integers.
(Note: The input row and Col guarantee 0 < row < 0 < col < 100) output output each integer in the traversal order. Each integer occupies one row. Sample input
4 4
1 2 3 4,
5,
6 10, 9 8
7
Sample output
1
2
3
4
5
6
7
8
9
Ten
-
15
16
#include
int main ()
{
int n,m,i,j,t=1,x=0,y=0;
int a[100][100],b[100][100]={0};
scanf ("%d%d", &n,&m);
for (i=0;i=0&&!b[x][y-1])//by row from right to left
{
b[x][y--]=t++;
printf ("%d\n", A[x][y]);
}
while (X-1>=0&&!b[x-1][y])//By column from bottom to top traversal
{ b[x--][y]=t++;
printf ("%d\n", A[x][y]);
}
}
return 0;
}