← 查看本卷题目
组合题5 个小题
已作答 0 / 5

完善程序 (子矩阵)给输入一个 n1×m1n_1\times m1 的矩阵 aa,和 n2×m2n_2\times m_2 的矩阵 bb,问 aa 中是否存在子矩阵和 bb 相等。若存在,输出所有子矩阵左上角的坐标:若不存在输出 There is no answer\texttt{There is no answer}。

#include<iostream>using namespace std; const int SIZE = 50; int n1,m1,n2,m2,a[SIZE][SIZE],b[SIZE][SIZE]; int main(){    int i,j,k1,k2;    bool good ,haveAns;     cin>>n1>>m1;    for(i=1;i<=n1;i++)       for(j=1;j<=m1;j++)          cin>>a[i][j];     cin>>n2>>m2;    for(i=1;i<=n2;i++)       for(j=1;j<=m2;j++)           [   ①     ];     haveAns=false;    for(i=1;i<=n1-n2+1;i++)       for(j=1;j<= [    ②     ];j++){            [   ③    ];           for(k1=1;k1<=n2;k1++)               for(k2=1;k2<=[    ④    ] ;k2++){                  if(a[i+k1-1][j+k2-1]!=b[k1][k2])                     good=false;               }          if(good){             cout<<i<<' '<<j<<endl;             [       ⑤      ];          }       }    if(!haveAns)       cout<<"There is no answer"<<endl;     return 0;} 
第 28 题填空题

②处应填( )

填写答案