(子矩阵)输入一个 n1*m1 的矩阵 a,和 n2*m2 的矩阵 b,问 a 中是否存在子矩阵和 b 相等。 若存在, 输出所有子矩阵左上角的坐标; 若不存在输出 “There is no answer” 。
Const SIZE = 50;
Var
n1, m1, n2, m2, i, j, k1, k2 : Integer;
a, b : Array[1..SIZE, 1..SIZE] Of Integer;
good, haveAns : Boolean;
Begin Readln(n1, m1);
For i := 1 To n1 Do
For j := 1 To m1 Do
Read(a[i][j]);
Readln(n2, m2);
For i := 1 To n2 Do
For j := 1 To m2 Do
read(b[i][j]) ;
haveAns := FALSE;
For i := 1 To n1 - n2 + 1 Do
For j := 1 To m1-m2+1 Do
Begin
good:=true ;
For k1 := 1 To n2 Do
For k2 := 1 To m2 Do
If a[i + k1 - 1][j + k2 - 1] <> b[k1][k2] Then
good := FALSE;
If good Then
Begin
Writeln(i, ' ', j);
haveAns:=true
End;
End;
If NOT haveAns Then
Writeln('There is no answer');
End.