#C1818. Rotate Matrix
Rotate Matrix
Rotate Matrix
Given an \(n \times n\) matrix, your task is to rotate the matrix by 90 degrees clockwise. The rotation must be done in-place, i.e. you should not allocate another matrix for the rotation.
The rotation can be achieved in two steps:
- Transpose the matrix.
- Reverse each row.
Mathematically, if the input matrix is \(A\) and the rotated matrix is \(B\), then for each \(0 \le i,j < n\), the relation is:
$$ B[i][j] = A[n-1-j][i] $$
inputFormat
The first line of input contains an integer \(n\), the number of rows (and columns) of the matrix. Each of the following \(n\) lines contains \(n\) space-separated integers representing a row of the matrix.
outputFormat
Output the rotated matrix. Each of the \(n\) lines should contain \(n\) space-separated integers representing a row of the rotated matrix.
## sample3
1 2 3
4 5 6
7 8 9
7 4 1
8 5 2
9 6 3
</p>