071502 - Matrix operations

題目敘述 Problems Description:

請寫一個程式可以輸入一個任意大小的矩陣,並具備以下功能:

  1. 改變矩陣形狀

  2. 矩陣相乘(若無法相乘輸出fail)

  3. 轉置矩陣

  4. 矩陣輸出

  5. 結束

Please write a program that can input a matrix of any size and has the following functions:

  1. Change the shape of the matrix

  2. Multiply the matrix (If the input matrix cannot be multiplied ,then output “fail”)

  3. Transpose the matrix

  4. Output the matrix

  5. End

輸入說明 Input Description:

首先輸入矩陣的大小、矩陣中的值,最後重複輸入功能代號,且輸入的值皆為整數。

Input the size of the matrix and the values in the matrix. Then keep input the request number. By the way, it always inputs integers.

輸出說明 Output Description:

先輸出request:,然後再輸出對應功能代號的結果。

First, print request:, and then output the result of the corresponding request number.

輸入範例 Input Example:

2 3 1 2 3 1 1 1 1 3 2 4 2 2 3 1 1 1 1 1 1 4 2 2 3 2 2 2 2 2 2 3 4 5

輸出範例 Output Example:

request: request: [[1 2] [3 1] [1 1]] request: request: [[3 3 3] [4 4 4] [2 2 2]] request: fail request: request: [[3 4 2] [3 4 2] [3 4 2]] request:

提示 Hint:

最后更新于

这有帮助吗?