#C12129. Rotate Matrix 90° Clockwise
Rotate Matrix 90° Clockwise
Rotate Matrix 90° Clockwise
In this problem, you are given a two-dimensional matrix of integers. Your task is to rotate the matrix by 90° clockwise. The rotation operation transforms the matrix such that the element at position ( (i, j) ) in the original matrix moves to position ( (j, n-1-i) ) in the rotated matrix, where ( n ) is the number of rows in the original matrix.
For example, if the matrix is:
1 2 3
4 5 6
7 8 9
After rotating 90° clockwise, it becomes:
7 4 1
8 5 2
9 6 3
Note that the given matrix can be non-square. In that case, after rotation, the dimensions of the matrix will be swapped.
inputFormat
The input is read from standard input. The first line contains two integers ( R ) and ( C ), representing the number of rows and columns of the matrix, respectively. This is followed by ( R ) lines, each containing ( C ) space-separated integers representing the matrix elements.
outputFormat
Print the rotated matrix to standard output. Each line of the output should represent a row of the rotated matrix, with the integers on each line separated by a single space.## sample
3 3
1 2 3
4 5 6
7 8 9
7 4 1
8 5 2
9 6 3
</p>