#K38867. Rotate Matrix 90 Degrees Clockwise

    ID: 26294 Type: Default 1000ms 256MiB

Rotate Matrix 90 Degrees Clockwise

Rotate Matrix 90 Degrees Clockwise

Given a square matrix of size \(n \times n\), write a program to rotate the matrix by 90 degrees clockwise. The rotated matrix should be output in the same format as the input.

Example:

Input:
3
1 2 3
4 5 6
7 8 9

Output: 7 4 1 8 5 2 9 6 3

</p>

The task is to implement the matrix rotation function and then apply it to the input read from standard input (stdin). The rotated matrix must be printed to standard output (stdout) with each row on a new line.

inputFormat

The first line of input contains an integer \(n\) indicating the size of the matrix. The next \(n\) lines each contain \(n\) space-separated integers representing the rows of the matrix.

For example:

3
1 2 3
4 5 6
7 8 9

outputFormat

Output the rotated matrix in \(n\) lines where each line contains \(n\) space-separated integers. The matrix must be rotated 90 degrees clockwise.

For example, the above input should produce:

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

8 5 2 9 6 3

</p>