题目链接:
AC代码:
1 #include2 #include 3 #include 4 #include 5 #include 6 #include 7 #include 8 using namespace std; 9 char ss[1010][1010];10 #define MAX 2711 struct trie12 {13 trie *next[MAX];14 int v;15 trie()16 {17 int i;18 v=0;19 for(i=0; i<26; i++) next[i]=NULL;20 }21 };22 trie *p,*q;23 void creattrie(char *str,trie *root)24 {25 int len = strlen(str);26 p = root;27 for(int i=0;i next[id] == NULL)31 {32 q=new trie;33 q->v = 1;34 p->next[id] = q;35 p=q;36 }37 else38 {39 p=p->next[id];40 p->v+=1;41 }42 }43 }44 int findtrie(char *str,trie *root)45 {46 int i;47 int len = strlen(str);48 p = root;49 for(i=0;i next[id];53 if(p->v == 1)54 {55 return i+1;56 }57 }58 }59 int main()60 {61 int T,n,ans;62 scanf("%d",&T);63 while(T--)64 {65 ans = 0;66 trie *root = new trie;67 scanf("%d",&n);68 //getchar();69 for(int i=0;i