#C12500. Rotate Matrix 90 Degrees Clockwise

    ID: 41935 Type: Default 1000ms 256MiB

Rotate Matrix 90 Degrees Clockwise

Rotate Matrix 90 Degrees Clockwise

You are given a square matrix \( A \) of size \( n \times n \). Your task is to rotate the matrix by 90 degrees clockwise. The problem requires you to read the matrix from standard input and output the rotated matrix to standard output.

The transformation can be described in two steps:

  1. Transpose the matrix. In other words, convert the element \( A[i][j] \) to \( A[j][i] \).
  2. Reverse each row of the transposed matrix.

Implement the transformation and ensure that your solution handles matrices of various sizes ranging from \(1 \times 1\) to larger sizes.

inputFormat

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

Example:

3
1 2 3
4 5 6
7 8 9

outputFormat

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

Example Output for the sample input:

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>