Trie字典树 模板
Trie树详解:https://www.cnblogs.com/llllllpppppp/p/9449846.html
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define inf 0x3f3f3f3f
#define mem(a,b) memset(a,b,sizeof(a))
bool vis[100005];
int trie[505][505];
int pin;
void insert(string s) //构建Trie数组
{
int i,u=1;
for(i=0;i<s.length();i++)
{
int t=s[i]-'a';
if(!trie[u][t])
trie[u][t]=pin++;
u=trie[u][t];
}
vis[u]=1;
}
int find(string s) //从Trie树中查找字符串
{
int i,u=1;
for(i=0;i<s.length();i++)
{
int t=s[i]-'a';
if(!trie[u][t])
return 0;
u=trie[u][t];
}
return 1;
}
int main() //查找n个字符串中是否含有字符串S2
{
int n,i;
string s1,s2;
pin=0;
mem(vis,0);
cin>>n;
while(n--)
{
cin>>s1;
insert(s1);
}
cin>>s2;
if(find(s2))
cout<<"YES"<<endl;
else
cout<<"NO"<<endl;
return 0;
}