Oneself is too lazy, do not have to write another code, this is another blog directly to find, its array template written very good, pointer template general like it! ~~
http://blog.csdn.net/king_cannon_fodder/article/details/77175620
Here is an example of the number of occurrences of the query string after the input string # include <bits/stdc++.h> #define MAXN 1000000using namespace std;struct trie{int next[2 6];///indicates whether the next node exists, the data field of the Int val;///node, can be changed as needed} Tree[maxn];int NXT;///NXT represents the number of the node char str[26];///stores the input string int add () {/ Establish a new node memset (&TREE[NXT], 0, sizeof (Trie)); return nxt++;} void Insert (char *s)///insert and build {int rt = 0, Len = strlen (s); for (int i = 0; i < len; i++) {int c = s[i]-' a '; if (!tree[rt].next[c]) {///If the node does not already exist in the tree, open a new node tree[rt].next[c] = Add (); } RT = Tree[rt].next[c]; The tree[rt].val++;///maintains the data field (this indicates the number of occurrences)}bool find (char *s) {///finds the string if there is an int rt = 0, Len = strlen (s); for (int i = 0; i < len; i++) {int c = s[i]-' a '; if (!tree[rt].next[c]) return false; RT = Tree[rt].next[c]; } if (Tree[rt].val) return true; return false;} int main () {int T; memset (&tree[0], 0, sizeof (Trie)); NXT = 1; scanf("%d", &t); while (t--) {scanf ("%s", str); Insert (str); } while (~SCANF ("%s", str)) {if (Find (str)) puts ("exist"); Else puts ("none"); } return 0;}
An array template is actually a mock pointer! ! ~
Dictionary Tree Array Template