You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

40 lines
1.0 KiB

#include <bits/stdc++.h>
using namespace std;
const int N = 110;
int a[N][N], b[N][N], c[N][N];
int n, m, p, q;
int main() {
cin >> n >> m;
for (int i = 0; i < n; i++)
for (int j = 0; j < m; j++)
cin >> a[i][j];
cin >> p >> q;
for (int i = 0; i < p; i++)
for (int j = 0; j < q; j++)
cin >> b[i][j];
if (m != p)
cout << "Error: " << m << " != " << p;
else {
cout << n << " " << q << endl;
for (int i = 0; i < n; i++)
for (int j = 0; j < q; j++)
for (int k = 0; k < m; k++)
c[i][j] += a[i][k] * b[k][j];
for (int i = 0; i < n; i++) {
for (int j = 0; j < q; j++) {
if (j == q - 1)
cout << c[i][j]; //注意每行最后一个数字后没有空格
else
cout << c[i][j] << " ";
}
if (i != n - 1)
cout << endl;
}
}
return 0;
}