#K14881. Matrix Rotation

    ID: 24233 Type: Default 1000ms 256MiB

Matrix Rotation

Matrix Rotation

You are given an \( N \times N \) matrix. Your task is to rotate the matrix by 90° clockwise. In other words, if the given matrix is \( M \), you need to produce a new matrix \( M' \) such that:

\[ M'_{i,j} = M_{N-1-j,i} \]

The input consists of an integer \( N \) representing the dimensions of the matrix, followed by \( N \) lines each containing \( N \) integers. The output should be the rotated matrix, with each row printed on a new line and each element separated by a space.

For example, a 3x3 matrix:

1 2 3
4 5 6
7 8 9
will be rotated to:
7 4 1
8 5 2
9 6 3

inputFormat

The first line contains an integer N (1 ≤ N ≤ 1000). Each of the following N lines contains N space-separated integers representing the rows of the matrix.

outputFormat

Output the rotated matrix. Each of the N lines should contain N space-separated integers representing a row of the rotated matrix.## sample

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

8 5 2 9 6 3

</p>