#K70157. Rotate Matrix 90° Clockwise

    ID: 33246 Type: Default 1000ms 256MiB

Rotate Matrix 90° Clockwise

Rotate Matrix 90° Clockwise

Given an (N\times N) matrix, rotate the matrix by 90° clockwise.

You are provided with a square matrix as input. Your task is to rotate the matrix in place (with minimal extra memory usage) by 90° clockwise and then output the modified matrix. The input is read from standard input, and the rotated matrix should be printed to standard output.

The rotation can be performed by first transposing the matrix and then reversing each row. For example, a 3x3 matrix:
(\begin{bmatrix}1 & 2 & 3\4 & 5 & 6\7 & 8 & 9\end{bmatrix}) becomes
(\begin{bmatrix}7 & 4 & 1\8 & 5 & 2\9 & 6 & 3\end{bmatrix}).

inputFormat

The first line contains an integer (N) indicating the dimension of the matrix. This is followed by (N) lines, each containing (N) space-separated integers representing the rows of the matrix.

outputFormat

Print the rotated matrix, with each row on a new line. The integers in each row should be separated by a single space.## sample

3
1 2 3
4 5 6
7 8 9
7 4 1

8 5 2 9 6 3

</p>