-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathgride_search.cpp
73 lines (64 loc) · 1.7 KB
/
gride_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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
#include<bits/stdc++.h>
using namespace std;
void printMat(vector<vector<int>>& G){
int m = G.size();
int n = G[0].size();
for(int i=0; i<m; i++){
for(int j=0; j<n; j++){
cout<<G[i][j]<<" ";
}
cout<<"\n";
}
}
int main(){
int T;
cin>>T;
while(T-- > 0){
int R,C,r,c,i,j,k,l;
cin>>R>>C;
vector<vector<char> > G, P;
G.resize(R, vector<char>(C, 0));
for(i=0; i<R; i++){
for(j=0; j<C; j++){
cin>>G[i][j];
}
}
cin>>r>>c;
P.resize(r, vector<char>(c, 0));
for(i=0; i<r; i++){
for(j=0; j<c; j++){
cin>>P[i][j];
}
}
//printMat(G);
//printMat(P);
int cflag = 0, final_flag = 0;
for(i=0; i<=R-r; i++){
for(j=0; j<=C-c; j++){
if(G[i][j] == P[0][0]){
cflag = 1;
for(k=0; k<r; k++){
if(cflag == 0)
break;
for(l=0; l<c; l++){
if(P[k][l] == G[i+k][j+l]){
if(k==r-1 && l==c-1 && cflag==1)
final_flag = 1;
cflag = 1;
}
else{
cflag = 0;
break;
}
}
}
}
}
}
if(final_flag == 1)
cout<<"YES\n";
else
cout<<"NO\n";
}
return 0;
}