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