#C9944. In-place Matrix Rotation
In-place Matrix Rotation
In-place Matrix Rotation
You are given an n x n square matrix. Your task is to rotate the matrix in-place by 90° clockwise. That is, modify the given matrix so that the element originally at \( A_{ij} \) moves to \( A_{j, n-i-1} \). The transformation can be performed by first taking the transpose of the matrix and then reversing each row.
Note: You are required to read the input from standard input (stdin
) and write the output to standard output (stdout
).
inputFormat
The first line contains an integer ( n ) representing the number of rows (and columns) of the matrix. The following ( n ) lines each contain ( n ) space-separated integers representing the matrix elements.
outputFormat
Print the rotated matrix. Each of the ( n ) lines should contain ( n ) space-separated integers representing a row of the matrix after a 90° clockwise rotation.## sample
3
1 2 3
4 5 6
7 8 9
7 4 1
8 5 2
9 6 3
</p>