#C14657. Matrix Transposition
Matrix Transposition
Matrix Transposition
You are given a matrix of integers that might be non-rectangular. That is, each row may have a different number of elements. Your task is to compute the transpose of the given matrix.
The transpose of a matrix is defined such that the element at row i and column j in the original matrix becomes the element at row j and column i in the transposed matrix. If a particular cell does not exist in the original matrix (because the row is shorter), then treat this missing entry as None
.
For example, given the matrix:
$$ \begin{bmatrix} 1 & 2 \\ 3 & 4 & 5 \\ 6 \end{bmatrix} $$Its transpose will be:
$$ \begin{bmatrix} 1 & 3 & 6 \\ 2 & 4 & \text{None} \\ \text{None} & 5 & \text{None} \end{bmatrix} $$inputFormat
The first line of input contains a single integer m representing the number of rows in the matrix.
Each of the following m lines contains space-separated integers representing the elements of that row. Note that the rows can have different numbers of integers.
If m is zero, the matrix is empty.
outputFormat
Output the transposed matrix with each row on a separate line. For each row in the transposed matrix, print its elements separated by a single space. For positions where the original matrix did not have an element, output the string None
(without quotes).
2
1 2 3
4 5 6
1 4
2 5
3 6
</p>