All problems

Rotate Matrix 90 Degrees

mediumPythonMatrices

Ferngrove Tiles previews floor plans as a square grid of colour codes. Customers viewing a plan on a phone turn the handset sideways, so the shop's software has to re-issue the same grid given a quarter turn to the right: what was the top row of the plan ends up running down the right-hand side.

Task: Print the grid turned 90 degrees clockwise.

Input

The first line holds an integer n, the side length of the grid, with 1 <= n <= 100. Each of the next n lines holds n integers separated by single spaces.

Output

n lines, each holding n integers separated by single spaces: the grid after the quarter turn. Clockwise means the value in the top-left corner of the original finishes in the top-right corner.

Example:

Input:
2
1 2
3 4

Output:
3 1
4 2

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

Discussion

Sign in to join the discussion — reading is open to everyone.

Loading comments…