-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy paththeGridSearch.java
More file actions
61 lines (54 loc) · 1.77 KB
/
theGridSearch.java
File metadata and controls
61 lines (54 loc) · 1.77 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
// https://www.hackerrank.com/challenges/the-grid-search/problem
import java.io.*;
import java.util.*;
import java.text.*;
import java.math.*;
import java.util.regex.*;
public class Solution {
static String gridSearch(String[] g, String[] p, int C, int c) {
int i,j,k,ans=1;
for(i=0;i<=g.length-p.length;i++)
{
for(j=0;j<=C-c;j++)
{
ans=1;
for(k=0;k<p.length;k++)
{
System.out.println(g[i+k].substring(j,j+c)+" "+p[k]);
System.out.println(g[i+k].substring(j,j+c)==p[k]);
if(g[i+k].substring(j,j+c)!=p[k])
{
System.out.println(g[i+k].substring(j,j+c)+" "+p[k]);
ans=0;
break;
}
}
if(ans==1)
return "YES";
System.out.println();
}
}
return "NO";
}
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int t = in.nextInt();
for(int a0 = 0; a0 < t; a0++){
int R = in.nextInt();
int C = in.nextInt();
String[] G = new String[R];
for(int G_i = 0; G_i < R; G_i++){
G[G_i] = in.next();
}
int r = in.nextInt();
int c = in.nextInt();
String[] P = new String[r];
for(int P_i = 0; P_i < r; P_i++){
P[P_i] = in.next();
}
String result = gridSearch(G, P, C, c);
System.out.println(result);
}
in.close();
}
}