#C7884. Matrix Rotation

    ID: 51804 Type: Default 1000ms 256MiB

Matrix Rotation

Matrix Rotation

You are given a matrix with n rows and m columns. Your task is to rotate the matrix by 90° clockwise and output the resulting matrix.

The rotation can be understood by the following transformation. Given an original matrix \(A\) of size \(n \times m\), the rotated matrix \(B\) will have size \(m \times n\) and each element is defined as:

[ B_{j+1,i+1} = A_{n-i,j+1} ]

For example, if the input matrix is:

1 2 3
4 5 6
7 8 9

Then the output (rotated matrix) will be:

7 4 1
8 5 2
9 6 3

The input and output are handled via standard input/output streams.

inputFormat

The first line contains two integers \(n\) and \(m\), denoting the number of rows and columns of the matrix, respectively.

The next \(n\) lines each contain \(m\) space-separated integers representing the rows of the matrix.

outputFormat

Output the rotated matrix, where each row is printed on a new line and the elements within a row are 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>