#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<iostream>
using namespace std;
struct Trie{
int child[10000][26];
int val[10000];
int size;
void init(){
memset(child[1],0,sizeof(child[1]));
size=1;
}
void insert(char p[]){
int base='a';
int u=0;
int len=strlen(p);
for(int i=0;i<len;i++){
if(!child[u][p[i]-base]){
val[u]=0;
child[u][p[i]-base]=size++;
}
val[u]++;
u=child[u][p[i]-base];
}
}
bool query(char p[]){
int u=0;
int len=strlen(p);
for(int i=0;i<len;i++){
if(!child[u][p[i]-'a'])return 0;
u=child[u][p[i]-'a'];
}
return 1;
}
}trie;
int main(){
int i,j,k,m,n;
scanf("%d",&n);
trie.init();
char s[2000];
while(n--){
cin>>s;
trie.insert(s);
}
cin>>n;
while(n--){
cin>>s;
if(trie.query(s))cout<<"Yes"<<endl;
else cout<<"No"<<endl;
}
return 0;
}
/*
5
xiaohao
wzw
llz
xeg
cn
4
*/
转载于:https://www.cnblogs.com/brodrinkwater/p/7528000.html