cswork / OAOpen practice workspace

Capital OneOA #3

Robot Matrix Commands

Estimated MediumJudge-ready

Topics (AI-labelled)SimulationIn-place Arrays

Execute row/column swaps, reversals, and clockwise rotations in order. Coordinates use 0-based indices.

Input

r c; then r lines of the matrix; then q; then q lines of commands. A command is swapRows r1 r2, swapColumns c1 c2, reverseRow r, reverseColumn c, or rotate90Clockwise. The matrix must be square when it is rotated. Site supplement: r,c≤50, q≤500.

Output

Output the final matrix, one row per line, with values separated by spaces.

Example 1

Input:

2 3
1 2 3
4 5 6
3
swapRows 0 1
reverseColumn 1
swapColumns 0 2

Output:

6 2 4
3 5 1

Example 2

Input:

2 2
1 2
3 4
1
rotate90Clockwise

Output:

3 1
4 2

Example 3

Input:

3 2
1 2
3 4
5 6
2
reverseRow 1
reverseColumn 0

Output:

5 2
4 3
1 6

Editorial

Loading solution…