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

TOP

返回列表