题目:http://acm.hdu.edu.cn/showproblem.php?pid=1247
1 #include<iostream> 2 #include<stdio.h> 3 #include<math.h> 4 #include<string.h> 5 #include<stdlib.h> 6 using namespace std; 7 char p[50005][30]; 8 struct tree{//建立树 9 struct tree *next[26]; 10 int n; 11 }*root;//根 12 13 void insert(char *p)//字典树添加 14 { 15 struct tree *now,*cur=root; 16 int len=strlen(p); 17 for(int i=0;i<len;i++) 18 { 19 if(cur->next[p[i]-'a']==NULL)//判断字母节点是否存在 20 { 21 now=(struct tree*)malloc(sizeof(struct tree));//分配空间 22 for(int j=0;j<26;j++) 23 { 24 now->next[j]=NULL;//初始化 25 } 26 now->n=0;//初始化 27 cur->next[p[i]-'a']=now; 28 cur=cur->next[p[i]-'a']; 29 } 30 else 31 { 32 cur=cur->next[p[i]-'a']; 33 } 34 } 35 cur->n=1;//字母存在并标记为1 36 } 37 38 int find2(char *p)//查找后缀树 39 { 40 struct tree *cur=root; 41 for(;*p!='