Problem Description
Description
Calculate the product of two matrices A and B.
Input
The first line contains three positive integers m, p, and n, with 0<=m,n,p<=10, indicating that matrix A has m rows and p columns, and matrix B has p rows and n columns;
The next m lines contain matrix A, with p integers per line separated by spaces;
The last p lines contain matrix B, with n integers per line separated by spaces.
Output
Output the product matrix: it should occupy m lines, with n values per line separated by spaces.
Sample Input
| |
Sample Output
| |
Problem Analysis
Matrix multiplication:
The value at the intersection of row m and column n of the result matrix equals the sum of the products of the corresponding entries in row m of the first matrix and column n of the second matrix.
Understanding matrix multiplication - Ruan Yifeng’s blog
You can also brute-force it with arrays,
but here we do it in a more advanced way:
overload operators on a struct,
so that we can perform struct multiplication directly,
and then just output the result.
| |
Problem link: ZZULI 1127 Matrix Product