编程题

(子矩阵)给输入一个n1*m1的矩阵a,和n2*m2的矩阵b,问a中是否存在子矩阵和b相等。

若存在,输出所有子矩阵左上角的坐标:若不存在输出“There isno answer”。


#include

using namespace std;


const int SIZE = 50;


int n1,m1,n2,m2,a[SIZE][SIZE],b[SIZE][SIZE];

int main()

{

\tint i,j,k1,k2;

\tbool good ,haveAns;


\tcin>>n1>>m1;

\tfor(i=1;i<=n1;i )

\t\tfor(j=1;j<=m1;j )

\t\t\tcin>>a[i][j];


\tcin>>n2>>m2;

\tfor(i=1;i<=n2;i )

\t\tfor(j=1;j<=m2;j )

\thaveAns=false;

\tfor(i=1;i<=n1-n2 1;i )

\t\tfor(j=1;j<= ;j ){

;

\tfor(k1=1;k1<=n2;k1 )

\t\tfor(k2=1;k2<= ;k2 ){

\t\t\tif(a[i k1-1][j k2-1]!=b[k1][k2])

\t\t\t\tgood=false;

\t\t}

\tif(good){

\t\tcout<

\t\t\t;

\t}

\t\t}

\tif(!haveAns)

\t\tcout<<"There is no answer"<

\treturn 0;

}

点赞(0) 打赏

评论列表 共有 0 条评论

暂无评论