返回列表 發帖
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. int main()
  4. {
  5.     int a1,b1,a2,b2;
  6.     cin>>a1>>b1;
  7.     int arr1[a1][b1];
  8.     for(int i=0;i<a1;i++)
  9.         for(int j=0;j<b1;j++)
  10.             cin>>arr1[i][j];
  11.     cin>>a2>>b2;
  12.     int arr2[a2][b2];
  13.     for(int i=0;i<a2;i++)
  14.         for(int j=0;j<b2;j++)
  15.             cin>>arr2[i][j];
  16.     if(b1!=a2)
  17.         cout<<"error"<<endl;
  18.     else
  19.     {
  20.         for(int i=0;i<a1;i++)
  21.         {
  22.             for(int j=0;j<b2;j++)
  23.             {
  24.                 int sum=0;
  25.                 for(int k=0;k<b1;k++)
  26.                     sum+=arr1[i][k]*arr2[k][j];
  27.                 if(j!=0)
  28.                     cout<<" ";
  29.                 cout<<sum;
  30.             }
  31.             cout<<endl;
  32.         }
  33.     }
  34.     return 0;
  35. }
複製代碼

TOP

返回列表