cswork / OAOpen practice workspace

CiscoOA #32

Rotate Matrix

Estimated EasyJudge-ready

Topics (AI-labelled)In-place Arrays

Rotate the given square matrix 90 degrees clockwise and output the rotated matrix; the direction is determined by the original example and cannot be changed to counterclockwise.

Input

The input is N M with N=M required, followed by N lines of M integers each. The original bounds only require a square matrix and give no numeric bounds; this site publicly adds 1≤N=M≤1000 and elements in −10^9..10^9.

Output

Output the rotated matrix as N lines, each with N space-separated integers; do not output the dimensions again.

Example 1

Input:

2 2
1 2
3 4

Output:

3 1
4 2

Example 2

Input:

1 1
7

Output:

7

Example 3

Input:

3 3
1 2 3
4 5 6
7 8 9

Output:

7 4 1
8 5 2
9 6 3

Example notes

The outputs of the three public examples are, in order: 3 1 / 4 2; 7; 7 4 1 / 8 5 2 / 9 6 3. Verified by independent enumeration or direct simulation.

Editorial

Loading solution…