#C13646. Rotate Square Matrix In-Place
Rotate Square Matrix In-Place
Rotate Square Matrix In-Place
Given an \(N \times N\) matrix, your task is to rotate the matrix by 90° clockwise in place. That means you should modify the matrix directly without using any extra matrix. The rotation must be done using swap operations between four corresponding elements in different layers.
For example, if you are given the following 3x3 matrix:
[ \begin{bmatrix} 1 & 2 & 3 \ 4 & 5 & 6 \ 7 & 8 & 9 \end{bmatrix} ]
After rotating it by 90° clockwise, the resulting matrix will be:
[ \begin{bmatrix} 7 & 4 & 1 \ 8 & 5 & 2 \ 9 & 6 & 3 \end{bmatrix} ]
</p>inputFormat
The input is read from standard input (stdin) and has the following format:
- The first line contains an integer \(N\) denoting the size of the matrix.
- The next \(N\) lines each contain \(N\) space-separated integers representing the rows of the matrix.
You can assume that \(N \ge 1\).
outputFormat
The output should be printed to standard output (stdout) as the rotated \(N \times N\) matrix. Each of the \(N\) lines should contain \(N\) space-separated integers corresponding to a row of the rotated matrix.
## sample3
1 2 3
4 5 6
7 8 9
7 4 1
8 5 2
9 6 3
</p>