Matrix Operations
Submit solution
C++, Python3
Points:
1
Time limit:
1.0s
Memory limit:
64M
Author:
Problem type
Allowed languages
In this problem you are tasked to simulate a series of matrix operations.
For any given matrix of \(N \times M\), the following actions can be performed:
1. Transpose (T)
1 2 3 4 1 5 9
5 6 7 8 -> 2 6 10
9 10 11 12 3 7 11
4 8 12
2. Rotate left (L)
1 2 3 4 4 8 12
5 6 7 8 -> 3 7 11
9 10 11 12 2 6 10
1 5 9
3. Rotate right (R)
1 2 3 4 9 5 1
5 6 7 8 -> 10 6 2
9 10 11 12 11 7 3
12 8 4
Input Specification
The first line will contain a single number \(K\) (\(K < 100\)), which is the number of test cases.
The following \(K\) test cases will each contain 3 parts, with the first line containing 2 integers \(N,M\) (\(0 < N,M < 100\)).
The next \(N\) lines will each contain \(M\) integers, describing the matrix.
The last line of each test case will be a string containing only T
L
R
letters. The maximum string length is \(50\).
Output Specification
The output should contain \(K\) parts, each the result of a single test case, which is the resulting matrix of that test case. Each part should be separated by a blank line.
Sample Input
2
3 4
1 2 3 4
5 6 7 8
9 10 11 12
TRRT
3 4
1 2 3 4
5 6 7 8
9 10 11 12
RLRLRL
Sample Output
12 11 10 9
8 7 6 5
4 3 2 1
1 2 3 4
5 6 7 8
9 10 11 12
Comments