#K6796. Rotate Grid 90 Degrees Clockwise

    ID: 32758 Type: Default 1000ms 256MiB

Rotate Grid 90 Degrees Clockwise

Rotate Grid 90 Degrees Clockwise

You are given an n x n grid (matrix) containing integer elements. Your task is to rotate the grid by \(90^\circ\) clockwise.

Details:

  • The input starts with an integer \(n\) which denotes the size of the grid.
  • Following that, there are \(n\) lines with \(n\) space-separated integers on each line representing the grid.
  • You need to output the rotated grid in the same format: \(n\) lines with \(n\) space-separated integers per line.

For example, rotating the grid below:

[ \begin{bmatrix} 1 & 2 & 3 \ 4 & 5 & 6 \ 7 & 8 & 9 \end{bmatrix} ]

results in:

[ \begin{bmatrix} 7 & 4 & 1 \ 8 & 5 & 2 \ 9 & 6 & 3 \end{bmatrix} ]

</p>

inputFormat

The input is read from standard input (stdin) and consists of:

  1. An integer \(n\) on the first line, representing the dimensions of the grid.
  2. \(n\) lines that follow, each containing \(n\) space-separated integers representing a row of the grid.

outputFormat

The rotated grid should be written to the standard output (stdout). The output must consist of \(n\) lines, each containing \(n\) space-separated integers corresponding to a row of the grid after a \(90^\circ\) clockwise rotation.

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

8 5 2 9 6 3

</p>