组合题5 个小题
已作答 0 / 5
完善程序 (子矩阵)给输入一个 n1×m1 的矩阵 a,和 n2×m2 的矩阵 b,问 a 中是否存在子矩阵和 b 相等。若存在,输出所有子矩阵左上角的坐标:若不存在输出 There is no answer。
1#include<iostream>2using namespace std;3 4const int SIZE = 50;5 6int n1,m1,n2,m2,a[SIZE][SIZE],b[SIZE][SIZE];7 8int main()9{10 int i,j,k1,k2;11 bool good ,haveAns;12 13 cin>>n1>>m1;14 for(i=1;i<=n1;i++)15 for(j=1;j<=m1;j++)16 cin>>a[i][j];17 18 cin>>n2>>m2;19 for(i=1;i<=n2;i++)20 for(j=1;j<=m2;j++)21 [ ① ];22 23 haveAns=false;24 for(i=1;i<=n1-n2+1;i++)25 for(j=1;j<= [ ② ];j++){26 [ ③ ];27 for(k1=1;k1<=n2;k1++)28 for(k2=1;k2<=[ ④ ] ;k2++){29 if(a[i+k1-1][j+k2-1]!=b[k1][k2])30 good=false;31 }32 if(good){33 cout<<i<<' '<<j<<endl;34 [ ⑤ ];35 }36 }37 if(!haveAns)38 cout<<"There is no answer"<<endl;39 40 return 0;41}42 ④处应填( )