码:
点击查看代码
struct Node{
bool isend;
int son[26];
int num;
}tir[N];
int tircnt = 1;
void tir_insert(string s){
int now = 0;
for(int i = 0; i < s.size(); i++){
int ch = s[i] - 'a';
if(tir[now].son[ch] == 0)
tir[now].son[ch] = tircnt++;
now = tir[now].son[ch];
tir[now].num++;
if(i == s.size() - 1) tir[now].isend = true;
}
}
int tir_find(string s){
int now = 0;
for(int i = 0; i < s.size(); i++){
int ch = s[i] - 'a';
if(tir[now].son[ch] == 0) return 0;
now = t[now].son[ch];
}
if(!tir[now].isend) return 0;
if(tir[now].num == 0) return 0;
return 1;
}