#C14521. In-Place 90-Degree Matrix Rotation
In-Place 90-Degree Matrix Rotation
In-Place 90-Degree Matrix Rotation
You are given an n x n matrix. Your task is to rotate this matrix by 90° clockwise in place.
In mathematical terms, for a matrix \(A\) of size \(n \times n\), the element originally at \(A[i][j]\) should be moved to \(A[j][n-1-i]\) after the rotation.
For example, the matrix:
1 2 3 4 5 6 7 8 9
should be transformed into:
7 4 1 8 5 2 9 6 3
The input is read from stdin and the resulting rotated matrix should be printed to stdout as described below.
inputFormat
The first line of input contains a single integer n
representing the dimensions of the square matrix (i.e., the matrix is n x n
).
This is followed by n
lines, each containing n
space-separated integers representing the matrix rows.
outputFormat
Output the rotated matrix, where each row is printed on a separate line, and the integers in each row are space-separated.
## sample3
1 2 3
4 5 6
7 8 9
7 4 1
8 5 2
9 6 3
</p>