在二维数组中找二维数组
int a[N][N] = { {1,2,3,0},{1,0,1,1},{0,1,-1,3},{1,0,2,2} };
int b[M][M] = { {2,3},{0,1} };
#include <iostream>
using namespace std;
#define N 4
#define M 2
int main() {
//在二维数组中找二维数组
int a[N][N] = { {1,2,3,0},{1,0,1,1},{0,1,-1,3},{1,0,2,2} };
int b[M][M] = { {2,3},{0,1} };
int i, j, F, k, c, count;
F = 0;
for (i = 0; i < N; i++) {
for (j = 0; j < N; j++) {
if (a[i][j] == b[0][0] && i+M<=N && j+M<=N ) {
count = 0;
for (c = 0; c < M; c++) {
for (k = 0; k < M; k++) {
if (a[i + c][j + k] == b[c][k]) {
count++;
}
}
}
if (count == M*M) {
F = 1;
cout << "found at (" << i + 1 << "," << j + 1 << ")"<<endl;
}
}
}
}
if (F == 0) {
cout << "not found!" << endl;
}
return 0;
}