1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43
| #include <iostream> #include <cstdio> #include <cstring>
int trie[100005][31], tot = 1; bool end[100005];
void Insert(char* s) { int len = strlen(s), p = 1;
for(int i = 0; i < len; i ++) { int ch = s[i] - 'a';
if(trie[p][ch] == 0) trie[p][ch] = ++ tot;
p = trie[p][ch]; }
end[p] = true; }
bool Search(char* s) { int len = strlen(s), p = 1;
for(int i = 0; i < len; i ++) { int ch = s[i] - 'a';
p = trie[p][ch];
if(!p) return false; }
return end[p]; }
int main() {
}
|