#P3106. Flip and Turn
Flip and Turn
Description
Let us define a set of operations on a rectangular matrix of printable characters. A matrix A with m rows (1-st index) and n columns (2-nd index) is given. The resulting matrix B is defined as follows. You are given a sequence of no more than 100 000 operations from the set. Apply the operations to the given matrix and output the resulting matrix.1
’): Bj,i = Ai,j2
’): Bn−j+1,m−i+1 = Ai,jH
’): Bm−i+1,j = Ai,jV
’): Bi,n−j+1 = Ai,jA
’), 180 (‘B
’), or 270 (‘C
’) degrees clockwise; 90 degrees case: Bj,m−i+1 = Ai,jX
’), 180 (‘Y
’), or 270 (‘Z
’) degrees counterclockwise; 90 degrees case: Bn−j+1,i = Ai,j
Input
At the first line of the input file there are two integer numbers — m and n (0 < m, n ≤ 300). Then there are m lines with n printable characters per line (we define a printable character as a symbol with ASCII code from 33 to 126 inclusive). There will be no additional symbols at these lines. The next line contains the sequence operations to be performed, specified by their one-character identifiers. The operations should be performed from left to right.
Output
Two integer numbers, the number of rows and columns in the output matrix. Then the output matrix must follow, in the same format as the input one.
3 4
0000
a0b0
cdef
A1
3 4
cdef
a0b0
0000
Source
Northeastern Europe 2005, Northern Subregion