#C322. Rotate Matrix by 90 Degrees Clockwise

    ID: 46623 Type: Default 1000ms 256MiB

Rotate Matrix by 90 Degrees Clockwise

Rotate Matrix by 90 Degrees Clockwise

You are given an n × n matrix. Your task is to rotate this matrix by 90° clockwise in place.

The operation can be described in two steps:

  1. Transpose the matrix. In other words, convert the matrix so that the element at index \(a_{ij}\) becomes the element at index \(a_{ji}\).
  2. Reverse each row of the transposed matrix.

Mathematically, if the input matrix is \(A = [a_{ij}]\), then after transposition, it becomes \(A^T = [a_{ji}]\) and after reversing each row, the resulting matrix becomes the rotated matrix.

This problem tests your understanding of matrix manipulation and in-place transformation.

inputFormat

The input is read from stdin and has the following format:

n
row1_element1 row1_element2 ... row1_elementn
row2_element1 row2_element2 ... row2_elementn
...
rown_element1 rown_element2 ... rown_elementn

Here, n is an integer representing the size of the matrix, followed by n lines, each containing n integers separated by spaces.

outputFormat

The output should be printed to stdout and consist of the rotated matrix in the same format as the input. Each row of the matrix should be printed on a separate line and the numbers in each row should be separated by a single space.

## sample
3
1 2 3
4 5 6
7 8 9
7 4 1

8 5 2 9 6 3

</p>