#C14330. Matrix Transformation Operations
Matrix Transformation Operations
Matrix Transformation Operations
You are given an ( m \times n ) matrix and an operation code. Your task is to transform the matrix based on the given operation as follows:
-
( op = 1 ): Transpose the matrix. In other words, the element at position ( (i, j) ) in the original matrix becomes the element at position ( (j, i) ) in the resulting matrix.
-
( op = 2 ): Rotate the matrix 90° clockwise. The first row becomes the last column, the second row becomes the second-to-last column, and so on.
-
( op = 3 ): Rotate the matrix 90° counterclockwise. The first column becomes the last row, the second column becomes the second-to-last row, etc.
Input is read from standard input (stdin) and the resulting matrix should be printed to standard output (stdout) with each row on a new line and elements separated by a single space.
( \textbf{Note:} ) The matrix is guaranteed to be non-empty.
inputFormat
The first line contains two integers, ( m ) and ( n ), separated by a space. Each of the next ( m ) lines contains ( n ) space-separated integers representing the matrix. The last line contains an integer ( op ) which indicates the operation to perform:
- 1: Transpose the matrix
- 2: Rotate the matrix 90° clockwise
- 3: Rotate the matrix 90° counterclockwise
outputFormat
Print the transformed matrix. Each row must be printed on a new line and the elements in each row should be space-separated.## sample
3 3
1 2 3
4 5 6
7 8 9
1
1 4 7
2 5 8
3 6 9
</p>