#K54367. Matrix Rotation: 90-Degree Clockwise
Matrix Rotation: 90-Degree Clockwise
Matrix Rotation: 90-Degree Clockwise
You are given a matrix with dimensions \( n \times m \). Your task is to rotate the matrix by 90° clockwise. In other words, the element originally at position \( (i,j) \) in the matrix will move to position \( (j, n-1-i) \) in the rotated matrix. For example, given a 3x3 matrix:
1 2 3 4 5 6 7 8 9
After rotation, it becomes:
7 4 1 8 5 2 9 6 3
Note that the rotated matrix will have dimensions \( m \times n \). Use standard input (stdin) to read the input and standard output (stdout) to print the resulting rotated matrix.
inputFormat
The first line of input contains two integers, \( n \) and \( m \), representing the number of rows and columns of the matrix respectively. The following \( n \) lines each contain \( m \) space-separated integers representing the matrix elements.
outputFormat
Output the rotated matrix. Each of the \( m \) rows should contain \( n \) space-separated integers representing the rotated matrix.
## sample3 3
1 2 3
4 5 6
7 8 9
7 4 1
8 5 2
9 6 3
</p>