#K13476. Matrix 90-Degree Clockwise Rotation
Matrix 90-Degree Clockwise Rotation
Matrix 90-Degree Clockwise Rotation
You are given an \(N \times N\) matrix. Your task is to rotate the matrix 90 degrees clockwise in place. This transformation is done by first transposing the matrix and then reversing each row.
For example, given the matrix:
[ \begin{bmatrix} 1 & 2 & 3 \ 4 & 5 & 6 \ 7 & 8 & 9 \end{bmatrix} ]
after a 90-degree clockwise rotation, it becomes:
[ \begin{bmatrix} 7 & 4 & 1 \ 8 & 5 & 2 \ 9 & 6 & 3 \end{bmatrix} ]
</p>You must read the matrix from standard input and print the rotated matrix to standard output. Each row of the matrix should be printed on a new line with the numbers separated by a space.
inputFormat
The first line of input contains an integer (N) representing the size of the matrix. The following (N) lines each contain (N) space-separated integers representing the rows of the matrix.
outputFormat
Output the rotated matrix, with each of the (N) lines containing (N) space-separated integers. No extra spaces or newline characters should be printed.## sample
3
1 2 3
4 5 6
7 8 9
7 4 1
8 5 2
9 6 3
</p>