forked from PoeLoren/hackerrank
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathThe Grid Search.cpp
52 lines (50 loc) · 1.42 KB
/
The Grid Search.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
using namespace std;
char a[1001][1001], b[1001][1001];
int main() {
/* Enter your code here. Read input from STDIN. Print output to STDOUT */
int T;
cin >> T;
while(T--){
int R, C, r, c;
cin >> R >> C;
for(int i = 0; i < R; ++i)
for(int j = 0; j < C; ++j)
cin >> a[i][j];
cin >> r >> c;
for(int i = 0; i < r; ++i)
for(int j = 0; j < c; ++j)
cin >> b[i][j];
bool res = false;
for(int i = 0; i < R - r + 1; ++i)
for(int j = 0; j < C - c + 1; ++j){
if(a[i][j] == b[0][0]){
bool flag = true;
for(int p = 0; p < r; ++p){
for(int q = 0; q < c; ++q){
if(a[i + p][j + q] != b[p][q]){
flag = false;
break;
}
}
if(flag == false)
break;
}
if(flag)
{
res = true;
break;
}
}
}
if(res)
cout << "YES" << endl;
else
cout << "NO" << endl;
}
return 0;
}