- #include<bits/stdc++.h>
- using namespace std;
- int main (){
- int a1,b1,a2,b2;
- cin >> a1 >> b1;
- int str1[a1][b1] = {{0},{0}};
- for (int i=0;i<a1;i++){
- for (int j=0;j<b1;j++){
- cin >> str1[i][j];
- }
- }
- cin >> a2 >> b2;
- int str2[a2][b2] = {{0},{0}};
- for (int i=0;i<a2;i++){
- for (int j=0;j<b2;j++){
- cin >> str2[i][j];
- }
- }
- int A[a1][b2] = {{0},{0}};
- if (a2 != b1){
- cout << "error" << endl;
- }
- else{
- for (int i=0;i<a1;i++){
- for (int j=0;j<b2;j++){
- for (int k=0;k<b1;k++){
- A[i][j] += str1[i][k]*str2[k][j];
- }
- }
- }
- for (int i=0;i<a1;i++){
- for (int j=0;j<b2;j++){
- cout << A[i][j];
- if (j != b2-1)
- cout << ' ';
- }
- cout << endl;
- }
- }
- return 0;
- }
複製代碼 |