天天看點

CODEVS 4189 : 字典

#include<cstdio>
#include<cstring>
using namespace std;

const int maxn=400000+100;

int trie[maxn][26],tot;

inline void insert(char* ch){
  
  int len=strlen(ch);
  int root=0;
  for(int i=0;i<len;i++){
    
    int ind=ch[i]-'a';
    if(!trie[root][ind]) trie[root][ind]=++tot;
    root=trie[root][ind];
  }
}

inline bool search(char* ch){
  
  int len=strlen(ch);
  int root=0;
  for(int i=0;i<len;i++){
    
    int ind=ch[i]-'a';
    if(!trie[root][ind]) return false;
    root=trie[root][ind];
  }
  return root!=0;
}

int main(){
  
  char ch[10];
  int n,m;
  scanf("%d",&n);
  while(n--){
    
    scanf("%s",ch);
    insert(ch);
  }
  scanf("%d",&m);
  while(m--){
    
    scanf("%s",ch);
    printf("%s\n",search(ch)?"YES":"NO");
  }
}