Untitled

mail@pastecode.io avatar
unknown
c_cpp
2 years ago
1.7 kB
2
Indexable
Never
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
char arr[1001][1001]; 
char find2[1001][1001]; 
string gridSearch(vector<string>g, vector<string>p){
      int b=g.size(),c=g[0].size();
      for (int i=0;i<b; i++)
      {
            for (int j=0;j<c; j++)
            {
                  arr[i][j]=g[i][j];
            }
      }
      int d=p.size(),e=p[0].size();
      for (int i=0;i<d; i++)
      {
            for (int j=0;j<e; j++)
            {
                  find2[i][j]=p[i][j];
            }
      }
      if(d>b || e>c){return "NO";}
      int ans=0; 
      for (int z=0;z<=b-d; z++)
      {
            for (int zz=0; zz<=c-e; zz++)
            {
                  int ck=0; 
                  for (int l=z; l<z+d; l++)
                  {
                        for (int ll=zz; ll<zz+e; ll++)
                        {
                              if (find2[l-z][ll-zz]!=arr[l][ll]){
                                    ck=1; break;    
                              }
                        }
                        if (ck==1)break; 
                  }
                  if (ck==0) {ans=1; break;}
            }
            if (ans==1) break; 
        }
        if (ans) return "YES";
        else return "NO";
}
int main() {
      int t;
      cin>>t;
      while(t--){
            int n,m,a,b,i;
            string s;
            vector<string>v,fin;
            cin>>n>>m;
            for(i=0;i<n;i++){
                  cin>>s;
                  v.pb(s);
            }
            cin>>a>>b;
            for(i=0;i<a;i++){
                  cin>>s;
                  fin.pb(s);
            }
            cout<<gridSearch(v,fin);
      }     
}