Lab1 - Specification

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 1

Q1.

Input format
The input begins with an integer n on a line, which means that there are n test cases.
And the first character of each following row is the command.
+ : add two matrices.
* : multiply two matrices.
p : print the matrix.
t : print the transpose of the matrix.

The size of each matrix is 3x3.


Each matrix contains nine integers.

E.g. , which a, b, c, d, e, f, g, h, i are nine integers.

Constraints
Use class and switch to implement.

Output Format
You must output the result after doing the calculation.

E.g. + 1 1 1 2 2 2 3 3 3 4 4 4 5 5 5 6 6 6 means

if the result number is , then you need to print [5, 5, 5, 7, 7, 7, 9, 9, 9].


space is needed.

Sample Input
7
p123456789
p100010001
+111222333444555666
+ -1 -1 -1 2 2 2 3 3 3 4 4 4 -5 -5 -5 6 6 6
* 5 -7 14 1 5 -2 -6 -21 4 0 0 0 0 0 0 0 0 0
* 1 2 1 2 4 2 1 2 1 -3 0 2 9 -5 11 -1 -4 8
t 789456123

Sample Output
[1, 2, 3, 4, 5, 6, 7, 8, 9]
[1, 0, 0, 0, 1, 0, 0, 0, 1]
[5, 5, 5, 7, 7, 7, 9, 9, 9]
[3, 3, 3, -3, -3, -3, 9, 9, 9]
[0, 0, 0, 0, 0, 0, 0, 0, 0]
[14, -14, 32, 28, -28, 64, 14, -14, 32]
[7, 4, 1, 8, 5, 2, 9, 6, 3]

You might also like