#C5561. Rotate Matrix 90 Degrees Clockwise
Rotate Matrix 90 Degrees Clockwise
Rotate Matrix 90 Degrees Clockwise
You are given a square matrix with dimensions \(N \times N\). Your task is to rotate the matrix by 90 degrees clockwise.
The rotation should be performed in-place if possible, but you may also create a new matrix to output the rotated result. For example, when the matrix is:
1 2 3 4 5 6 7 8 9
After rotation, the output matrix should be:
7 4 1 8 5 2 9 6 3
Input/Output
The program reads input from standard input (stdin) and writes output to standard output (stdout).
inputFormat
The first line of input is an integer \(N\), which denotes the number of rows (and columns) in the matrix. Each of the next \(N\) lines contains \(N\) space-separated integers representing the elements of the matrix.
If \(N = 0\), it represents an empty matrix.
outputFormat
Output the rotated matrix in \(N\) lines. Each line should contain \(N\) space-separated integers representing the row of the rotated matrix. If the input matrix is empty, output nothing.
## sample3
1 2 3
4 5 6
7 8 9
7 4 1
8 5 2
9 6 3
</p>