#C12996. Matrix Transposition
Matrix Transposition
Matrix Transposition
This problem requires you to compute the transpose of a given matrix. You are provided with an n × m matrix where each row is given on a separate line after the first line which indicates the number of rows. Your task is to output the transposed matrix (an m × n matrix) such that each row of the output corresponds to a column of the input matrix.
Important: If the input matrix is irregular (i.e. rows have different numbers of elements), output exactly Matrix rows have varying lengths.
and do not perform any further processing. If the matrix is empty (n = 0), output nothing.
Note: All formulas are expressed in LaTeX format. For instance, an n \(\times\) m matrix is represented as \(A \in \mathbb{R}^{n \times m}\).
inputFormat
The input is read from stdin and has the following format:
- The first line contains an integer r representing the number of rows in the matrix.
- The next r lines each contain space-separated integers representing the elements of that row.
Note that if r = 0, the matrix is empty.
outputFormat
The output should be written to stdout:
- If the matrix is valid (all rows have the same number of elements), output the transposed matrix. Each row of the transposed matrix should be printed on a new line with the numbers separated by a single space.
- If the matrix is empty, output nothing.
- If the matrix is irregular (i.e., rows have varying lengths), output exactly:
Matrix rows have varying lengths.## sample
2
1 2 3
4 5 6
1 4
2 5
3 6
</p>