字典树
int trie[SIZE][26], tot=1;//初始化,假设字符串由小写字母构成 bool ed[SIZE]; void ins(char *str) { int len=strlen(str),p=1; for(int k=0;k<len;k++) { int ch=str[k]-'a'; if(trie[p][ch]==0) trie[p][ch]=++tot; p=trie[p][ch]; } ed[p]=true; } bool sea(char *str) { int len=strlen(str),p=1; for(int k=0;k<len;k++) { int ch=str[k]-'a'; p=trie[p][ch]; if(p==0) return false; } return ed[p]; }

浙公网安备 33010602011771号