#C10495. Matrix Rotation
Matrix Rotation
Matrix Rotation
Given an M×N matrix, rotate it 90° clockwise.
The rotation algorithm can be thought of as first reversing the rows of the matrix and then taking the transpose. In other words, if the original matrix is \( A \), then the rotated matrix \( B \) is given by:
\( B[i][j] = A[\text{Rows}-1-j][i] \)
If the matrix is empty, output an empty result.
Example:
Input: 3 3 1 2 3 4 5 6 7 8 9</p>Output: 7 4 1 8 5 2 9 6 3
inputFormat
The input is read from standard input (stdin) with the following format:
- The first line contains two integers \( R \) and \( C \), representing the number of rows and columns of the matrix respectively.
- The next \( R \) lines each contain \( C \) space-separated integers representing a row of the matrix.
outputFormat
Output the rotated matrix to standard output (stdout) where each row of the resulting matrix is printed on a new line and the integers are separated by a single space.
## sample3 3
1 2 3
4 5 6
7 8 9
7 4 1
8 5 2
9 6 3
</p>