#C9016. 90 Degree Matrix Rotation
90 Degree Matrix Rotation
90 Degree Matrix Rotation
Given an \(N \times M\) matrix, rotate it 90° clockwise. This operation is common in image processing and data manipulation. In the rotated matrix, each element originally at position \( (i, j) \) will move to position \( (j, N-1-i) \).
For example, if the input matrix is:
1 2 3 4 5 6 7 8 9
then the rotated matrix will be:
7 4 1 8 5 2 9 6 3
inputFormat
The first line contains two integers \(N\) and \(M\), representing the number of rows and columns of the matrix respectively.
Then follow \(N\) lines, each containing \(M\) space-separated integers that form the matrix.
outputFormat
Output the rotated matrix. Each line of the output should contain the elements of a row of the rotated matrix separated by a space.
## sample3 3
1 2 3
4 5 6
7 8 9
7 4 1
8 5 2
9 6 3
</p>