Skip to content

Instantly share code, notes, and snippets.

@hanjae-jea
Forked from anonymous/Grid-Search.java
Created February 3, 2016 12:36
Show Gist options
  • Save hanjae-jea/44e0eef2ed2205d7a631 to your computer and use it in GitHub Desktop.
Save hanjae-jea/44e0eef2ed2205d7a631 to your computer and use it in GitHub Desktop.
import java.io.*;
import java.util.Scanner;
public class Slipp01{
static int R, C, r, c;
static String G[], P[];
public static void main(String args[]){
Scanner in = new Scanner(System.in);
int test_case = in.nextInt();
Boolean result = false;
for( int test = 0 ; test < test_case ; test ++){ // T
result = test(in);
if(result){
System.out.println("YES");
}else{
System.out.println("NO");
}
}
}
private static Boolean test(Scanner in){
R = in.nextInt();
C = in.nextInt();
G = new String[R];
for(int G_i=0; G_i < R; G_i++){
G[G_i] = in.next();
}
r = in.nextInt();
c = in.nextInt();
P = new String[r];
for(int P_i=0; P_i < r; P_i ++){
P[P_i] = in.next();
}
// 여기까지 데이터 입력 완료
for( int i = 0; i <= R-r; i ++ ){
int res = -1;
while(true) {
res = G[i].indexOf(P[0], res+1);
if( res == -1 ) break;
if (check(i, res))
return Boolean.TRUE;
}
}
return Boolean.FALSE;
}
private static Boolean check(int row, int col){
for( int checkRow = 1; checkRow < r; checkRow ++) {
int res = G[row + checkRow].indexOf(P[checkRow], col);
if (res == col) {
continue;
} else {
return Boolean.FALSE;
}
}
return Boolean.TRUE;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment