Submit | All submissions | Best solutions | Back to list |
Problem hidden
MATSPIR - Matrix Spiral Printing |
I am running of out stories here :(
You are given an N x M matrix. Print the matrix spirally.
Input
The first line contains two space seperated integers N and M.(1 <= N, M <= 50)
The next N lines contain M space seperated integers each. Each element of the matrix will be between 1 and 100.
Output
For each test case print N * M lines, each line containing one element of the matrix, as they appear in the spiral order traversal.
Example
Input
4 4
1 2 3 4
5 6 7 8
9 10 11 12
13 14 15 16
Output
1
2
3
4
8
12
16
15
14
13
9
5
6
7
11
10
Explanation
You can traverse the matrix spirally as shown in the image:
Added by: | kousik |
Date: | 2013-09-13 |
Time limit: | 1s |
Source limit: | 50000B |
Memory limit: | 1536MB |
Cluster: | Cube (Intel G860) |
Languages: | All except: ASM64 |
Resource: | Common problem |