#C7959. Rotate Matrix Clockwise
Rotate Matrix Clockwise
Rotate Matrix Clockwise
You are given an \(N \times N\) matrix. Your task is to rotate the matrix by 90° clockwise. The matrix will be provided in a standard input format where the first line represents \(N\), and the following \(N\) lines each contain \(N\) integers separated by spaces. Output the rotated matrix in the same format: each row on a new line with the numbers separated by a single space.
Note: Ensure that your solution reads input from standard input (stdin) and outputs the result to standard output (stdout). The matrix rotation algorithm involves transposing the matrix and then reversing the order of elements in each row.
inputFormat
The first line contains a single integer \(N\) representing the number of rows (and columns) in the matrix. Each of the next \(N\) lines contains \(N\) space-separated integers representing a row of the matrix.
Example:
3 1 2 3 4 5 6 7 8 9
outputFormat
Output the rotated matrix. Each of the \(N\) lines should contain \(N\) space-separated integers representing a row of the rotated matrix.
For the input above, the correct output is:
7 4 1 8 5 2 9 6 3## sample
3
1 2 3
4 5 6
7 8 9
7 4 1
8 5 2
9 6 3
</p>