A vineyard records its trellis-post labels as a rectangular grid: R rows of C short alphanumeric codes. Before shipping the grid to a new pruning rig that reads posts column-first instead of row-first, the vineyard's inventory system must rewrite the grid transposed — the label that sat in row i, column j must appear in row j, column i of the output.
Print exactly C lines. The j-th output line (1-indexed) contains R space-separated tokens: the token that was in row i, column j of the input, for i = 1..R in order — i.e., the grid transposed so its columns become rows.
Example 1
Input
2 3 A1 B2 C3 D4 E5 F6
Expected
A1 D4 B2 E5 C3 F6
Explanation
The grid has 2 rows and 3 columns. Column 1 holds A1 (row 1) and D4 (row 2), so the first output line is 'A1 D4'; column 2 holds B2 and E5, giving 'B2 E5'; column 3 holds C3 and F6, giving 'C3 F6'.
Example 2
Input
3 1 X Y Z
Expected
X Y Z
Explanation
The grid has 3 rows and 1 column. With only one column, the transposed grid has only one row, formed by reading down that column: X, Y, Z — so the single output line is 'X Y Z'.
Ready to solve this?
Sign in to open the editor, run your code against the sample tests, and submit against the full test suite.
Sign in to solve →