Flipping Rows and Columns
Fenwick Retail's sales extract arrives with one row per trading day and one column per product, which suits the daily report — a day's row is read straight off. The product managers want the same numbers the other way up: one row per product, running across the days, so a manager can follow a single product's line without hopping between rows. No number changes and none is dropped; the value recorded for a given day and a given product simply moves to the position where the product picks the row and the day picks the column.
Task: Print the extract with products as rows and days as columns.
Input
The first line holds two integers separated by a space: the number of rows (days) and the number of columns (products) in the extract. Each of the next rows lines holds cols values separated by single spaces.
Output
cols lines, each holding rows values separated by single spaces: one line per product, holding that product's value for each day in day order. Write each as a plain integer.
Example:
Input:
2 3
1 2 3
4 5 6
Output:
1 4
2 5
3 6
Sign in to solve this problem
Reading problems is free for everyone — solving them (Run, Submit, and tracking what you've solved) needs an account.
Sign in