#C4107. Matrix Rotation 90° Counterclockwise
Matrix Rotation 90° Counterclockwise
Matrix Rotation 90° Counterclockwise
Given an ( R \times C ) matrix, your task is to rotate it 90° counterclockwise. The rotation can be described by the formula:
[
B_{i,j} = A_{j, C-1-i}
]
where ( A ) is the original matrix and ( B ) is the rotated matrix. The input matrix may have different numbers of rows and columns. Make sure to handle edge cases such as a single row or a single column matrix.
Note: The matrix is provided from standard input and the rotated matrix must be printed to standard output with each row on one line and elements separated by a space.
inputFormat
The first line contains two space-separated integers ( R ) and ( C ), representing the number of rows and columns of the matrix, respectively. Each of the next ( R ) lines contains ( C ) space-separated integers representing the matrix elements.
outputFormat
Output the rotated matrix in the same format: each line corresponds to a row with space-separated integers. If the matrix is empty (i.e. ( R = 0 ) or ( C = 0 )), output nothing.## sample
3 3
1 2 3
4 5 6
7 8 9
3 6 9
2 5 8
1 4 7
</p>