#K1956. Rotate Matrix 90 Degrees Clockwise
Rotate Matrix 90 Degrees Clockwise
Rotate Matrix 90 Degrees Clockwise
Given an n × n square matrix, your task is to compute the matrix rotated by 90 degrees clockwise. The transformation can be described by the formula:
$$B_{ij} = A_{n-j+1,i}$$
where \(A\) is the original matrix and \(B\) is the rotated matrix. You will be given an integer n representing the size of the matrix, followed by n lines each containing n space-separated integers. Your program should output the rotated matrix in the same format, with each row on a new line and elements separated by a single space.
Test your solution with various square matrices including edge cases such as 1x1 matrices.
inputFormat
The first line contains an integer n, the dimension of the matrix. Each of the next n lines contains n space-separated integers representing the matrix.
outputFormat
Output the rotated matrix, with each row on a new line and each integer separated by a single space.## sample
3
1 2 3
4 5 6
7 8 9
7 4 1
8 5 2
9 6 3
</p>