We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
public static boolean calculate(int [][]A,int [][]a,int R,int C,int r,int c,int j,int k){
if(j+r<=R&&k+c<=C){
boolean flag = true;
for(int i1=0;i1<r;i1++){
for(int i2=0;i2<c;i2++){
if(A[j+i1][k+i2]!=a[i1][i2]){
flag=false;
break;
}
}
if(!flag)
break;
}
return flag;
}
else
return false;
}
public static void main(String[] args) {
/* Enter your code here. Read input from STDIN. Print output to STDOUT. Your class should be named Solution. */
Scanner in = new Scanner(System.in);
int t = in.nextInt();
boolean flag = false;
for(int i=0;i<t;i++){
int R = in.nextInt();
int C = in.nextInt();
int [][]A = new int[R][C];
String line;
for(int j=0;j<R;j++){
line = in.next();
for(int k=0;k<C;k++)
A[j][k]=Character.getNumericValue(line.charAt(k));
}
int r = in.nextInt();
int c = in.nextInt();
int [][]a = new int[r][c];
for(int j=0;j<r;j++){
line = in.next();
for(int k=0;k<c;k++)
a[j][k]=Character.getNumericValue(line.charAt(k));
}
for(int j=0;j<R;j++){
for(int k=0;k<C;k++){
if(A[j][k]==a[0][0])
if(calculate(A,a,R,C,r,c,j,k)){
flag = true;
break;
}
}
if(flag){
break;
}
}
if(flag)
System.out.println("YES");
else
System.out.println("NO");
}
}
}
//Works with your example
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
The Grid Search
You are viewing a single comment's thread. Return to all comments →
public class Solution {
}
//Works with your example