#C6450. Matrix Transformations
Matrix Transformations
Matrix Transformations
Given an integer matrix \(A\) and a sequence of transformation commands, your task is to apply these operations sequentially to the matrix and output the final result.
The allowed commands are:
- transpose: Compute the transpose of the matrix \(A\), i.e., \(A^T\) where \(A^T_{ij} = A_{ji}\).
- rotate_clockwise: Rotate the matrix 90° clockwise. In this transformation, an element \(A_{ij}\) moves to position \(A'_{j, n-1-i}\), where \(n\) is the number of rows.
- rotate_counterclockwise: Rotate the matrix 90° counterclockwise. Here, \(A_{ij}\) moves to \(A'_{m-1-j, i}\), where \(m\) is the number of columns.
- flip_horizontal: Flip the matrix horizontally by reversing each row.
- flip_vertical: Flip the matrix vertically by reversing the order of the rows.
Note that some operations may change the dimensions of the matrix. Apply the commands in the given order using the result of the previous operation as input for the next.
inputFormat
The input is provided via standard input (stdin) with the following format:
- The first line contains two integers (n) and (m), representing the number of rows and columns of the matrix.
- The next (n) lines each contain (m) integers, representing the rows of the matrix.
- The following line contains an integer (q), which specifies the number of transformation commands.
- The next (q) lines each contain a string representing a command. The command will be one of the following: "transpose", "rotate_clockwise", "rotate_counterclockwise", "flip_horizontal", or "flip_vertical".
outputFormat
Output the final transformed matrix to standard output (stdout). Each row should be printed on a separate line with the elements separated by a single space.## sample
2 2
1 2
3 4
1
transpose
1 3
2 4
</p>