#C9182. Rotate Matrix 90 Degrees Clockwise
Rotate Matrix 90 Degrees Clockwise
Rotate Matrix 90 Degrees Clockwise
You are given a 2D integer matrix representing an n×m grid. Your task is to rotate the matrix 90 degrees clockwise and output the resulting matrix. The rotated matrix will have dimensions m×n where each element is relocated according to the rotation. The transformation can be mathematically expressed in \( \LaTeX \) as:
\( B_{i,j} = A_{n-1-j,i} \)
where \(A\) is the original matrix with dimensions \(n \times m\) and \(B\) is the rotated matrix with dimensions \(m \times n\). This problem will test your ability to manipulate two-dimensional arrays and perform index transformations.
inputFormat
The first line of input contains two integers \(n\) and \(m\), representing the number of rows and columns of the matrix, respectively.
This is followed by \(n\) lines, each containing \(m\) space-separated integers that represent each row of the matrix.
outputFormat
Output the rotated matrix. The output should contain \(m\) lines, each line containing \(n\) space-separated integers representing the corresponding row of the rotated matrix in order.
## sample3 4
1 2 3 4
5 6 7 8
9 10 11 12
9 5 1
10 6 2
11 7 3
12 8 4
</p>