#C9164. Rotate Matrix In-Place
Rotate Matrix In-Place
Rotate Matrix In-Place
You are given a square matrix of size \(N \times N\). Your task is to rotate this matrix by 90° clockwise in-place (i.e. without using extra memory for another matrix).
The input is read from standard input (stdin). The first line contains the integer \(N\), representing the number of rows and columns. The next \(N\) lines each contain \(N\) space-separated integers representing the matrix. Your program should modify the matrix by rotating it 90° clockwise and then print the resulting matrix to standard output (stdout), with each row on a new line and each integer separated by a space.
Use the following algorithm conceptually: for each layer of the matrix, perform a circular swap of the corresponding elements from four sides.
Note: Make sure to handle edge cases such as when \(N = 1\).
inputFormat
The first line contains an integer N, the number of rows and columns. Each of the following N lines contains N space-separated integers representing the matrix.
outputFormat
Output the rotated matrix. Each of the N lines should contain N space-separated integers representing one row of the matrix.## sample
3
1 2 3
4 5 6
7 8 9
7 4 1
8 5 2
9 6 3
</p>