#K39477. Matrix Rotation

    ID: 26429 Type: Default 1000ms 256MiB

Matrix Rotation

Matrix Rotation

You are given an ( n \times n ) matrix and your task is to rotate it by 90° clockwise in-place. In other words, each element ( matrix[i][j] ) should be moved to ( matrix[j][n-1-i] ). If the matrix is empty, simply return an empty matrix.

This problem tests your ability to manipulate multi-dimensional arrays and implement in-place transformations without using extra space.

inputFormat

The first line of input contains a single integer ( n ) (where ( 0 \le n \le 1000 )) representing the dimensions of the matrix. Then, there are ( n ) lines each containing ( n ) integers separated by spaces representing the rows of the matrix.

outputFormat

Output the rotated matrix in the same format: each row should be printed on a new line with its elements separated by a single space.## sample

2
1 2
3 4
3 1

4 2

</p>