#K7871. Matrix Operations
Matrix Operations
Matrix Operations
You are given a task to perform one of three matrix operations based on the input command. The operations are as follows:
- Create Matrix: Given two positive integers \(r\) and \(c\), create an \(r \times c\) matrix initialized with zeros.
- Transpose Matrix: Given a matrix of size \(r \times c\), compute its transpose (an \(c \times r\) matrix). The transpose of a matrix \(A=[a_{ij}]\) is defined by \(A^T=[a_{ji}]\).
- Flatten Matrix: Given a matrix, output the flattened version of the matrix in row-major order as a single line.
The program reads the operation code and the relevant matrix data from standard input and prints the result to standard output.
Input Operation Codes:
- 1: Create Matrix
- 2: Transpose Matrix
- 3: Flatten Matrix
inputFormat
The input begins with a single integer representing the operation code.
- If the operation code is 1 (Create Matrix):
- The next line contains two space-separated integers \(r\) and \(c\), representing the number of rows and columns.
- If the operation code is 2 (Transpose Matrix) or 3 (Flatten Matrix):
- The next line contains two space-separated integers \(r\) and \(c\).
- Then follow \(r\) lines, each containing \(c\) space-separated integers representing the matrix rows.
All input is provided via stdin.
outputFormat
For operation 1 (Create Matrix) and 2 (Transpose Matrix):
- Print the resulting matrix with each row on a new line and the elements separated by a single space.
For operation 3 (Flatten Matrix):
- Print the flattened matrix as a single line with the elements separated by a single space.
All output must be printed to stdout.
## sample1
2 3
0 0 0
0 0 0
</p>