forked from derekhh/HackerRank
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy paththe-grid-search.cpp
More file actions
61 lines (58 loc) · 1.11 KB
/
the-grid-search.cpp
File metadata and controls
61 lines (58 loc) · 1.11 KB
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
53
54
55
56
57
58
59
60
61
/*
the-grid-search.cpp
The Grid Search
*/
#include <iostream>
#include <string>
#include <vector>
using namespace std;
vector<vector<int> > g, p;
int main() {
int t;
cin >> t;
while (t--) {
int R, C;
cin >> R >> C;
g.resize(R);
for (int i = 0; i < R; i++) {
string str;
cin >> str;
g[i].resize(C);
for (int j = 0; j < C; j++) {
g[i][j] = str[j] - '0';
}
}
int r, c;
cin >> r >> c;
p.resize(r);
for (int i = 0; i < r; i++) {
string str;
cin >> str;
p[i].resize(c);
for (int j = 0; j < c; j++) {
p[i][j] = str[j] - '0';
}
}
for (int i = 0; i < R - r + 1; i++) {
for (int j = 0; j < C - c + 1; j++) {
bool found = true;
for (int k = 0; k < r; k++) {
for (int l = 0; l < c; l++) {
if (g[i + k][j + l] != p[k][l]) {
found = false;
goto e1;
}
}
}
e1:
if (found) {
cout << "YES" << endl;
goto e2;
}
}
}
cout << "NO" << endl;
e2:;
}
return 0;
}