#C12026. Matrix 90° Clockwise Rotation
Matrix 90° Clockwise Rotation
Matrix 90° Clockwise Rotation
You are given an n x n matrix. Your task is to rotate the matrix by 90° clockwise and output the rotated matrix. The rotation should be performed using the following relation:
\( rotated[j][n-1-i] = matrix[i][j] \) for all valid \( i \) and \( j \), where \( n \) is the number of rows (or columns) of the matrix.
The input is provided in stdin and the resulting matrix should be printed to stdout, with each row on a separate line and each element separated by a space.
Examples:
Input: 4 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16</p>Output: 13 9 5 1 14 10 6 2 15 11 7 3 16 12 8 4
inputFormat
The first line contains an integer \( n \) representing the size of the matrix. The next \( n \) lines each contain \( n \) space-separated integers representing the rows of the matrix.
outputFormat
Output the rotated matrix, where each of the \( n \) lines contains \( n \) space-separated integers representing a row of the matrix after a 90° clockwise rotation.
## sample4
1 2 3 4
5 6 7 8
9 10 11 12
13 14 15 16
13 9 5 1
14 10 6 2
15 11 7 3
16 12 8 4
</p>