#C3693. Matrix Rotation

    ID: 47148 Type: Default 1000ms 256MiB

Matrix Rotation

Matrix Rotation

Given an \(N \times N\) matrix, rotate it by 90° clockwise in-place. The operation can be accomplished by first transposing the matrix and then reversing each row. Specifically, after the transpose, the element originally at position \(a_{ij}\) moves to \(a_{ji}\); then, reversing each row relocates \(a_{ji}\) to position \(a_{j, N-i-1}\).

For example, a matrix:

1 2 3
4 5 6
7 8 9

after rotation becomes:

7 4 1
8 5 2
9 6 3

inputFormat

The input begins with an integer (N) representing the matrix size. The next (N) lines contain (N) space-separated integers each, which define the rows of the matrix.

outputFormat

Output the rotated matrix in (N) lines where each line contains (N) space-separated integers representing the transformed row.## sample

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

8 5 2 9 6 3

</p>