#C14763. Rotate Matrix 90° Clockwise

    ID: 44448 Type: Default 1000ms 256MiB

Rotate Matrix 90° Clockwise

Rotate Matrix 90° Clockwise

You are given an N × N matrix. Your task is to rotate the matrix by 90° clockwise.

The rotation can be mathematically described by the following transformation. For each element \(a_{ij}\) of the matrix, its position in the rotated matrix becomes \(a'_{ji'}\) where \(i' = N - 1 - i\). That is, the rotated matrix \(R\) is given by:

[ R_{j, N-1-i} = A_{i,j} ]

Handle the edge cases such as an empty matrix or a 1×1 matrix appropriately.

inputFormat

The input is read from stdin and is formatted as follows:

  • The first line contains an integer N which represents the size of the matrix. If N is 0, the matrix is empty.
  • If N > 0, the next N lines each contain N space-separated integers representing one row of the matrix.

outputFormat

The output should be written to stdout and should display the rotated matrix in the same format as the input: each row on a new line with the elements separated by a single space. For an empty matrix, output nothing.

## sample
0