Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
Register

## 错在那里呢？大牛看看你就知道了？帮帮我！

Posted by chenxuan123456789 at 2012-08-05 15:38:42 on Problem 2001
```#include <stdio.h>
#include <malloc.h>
#include <string.h>
#define M 26
#define N 1000+10
char str1[N][30];
typedef struct Trie1
{
struct Trie1 *next[M];
int val;
}Trie;
Trie *root;
void init()
{
int i;
root=(Trie*)malloc(sizeof(Trie));
for(i=0;i<M;i++)
{
root->next[i]=NULL;
root->val=0;
}
}
void bulit(Trie *T,char str2[])
{
int i,id,length,j;
Trie *p,*q;
p=root;
length=strlen(str2);
for(i=0;i<length;i++)
{
id=str2[i]-'a';
if(p->next[id]==NULL)
{
q=(Trie*)malloc(sizeof(Trie));
for(j=0;j<M;j++)
{
q->next[j]=NULL;
q->val=0;
}
p->next[id]=q;
p->val++;
p=q;
}
else
{
p->val++;
p=p->next[id];
}
}
}
void find(Trie *T,char str[])
{
int i,id,length;
Trie *p=T;
length=strlen(str);
printf("%s ",str);
for(i=0;i<length;i++)
{
id=str[i]-'a';
p=p->next[id];
printf("%c",str[i]);
if(p->val==1)
break;
}
}
int main()
{
int i,n=0;
init();
while(scanf("%s",str1[n])!=EOF)
{
bulit(root,str1[n]);
n++;
}
for(i=0;i<n;i++)
{
find(root,str1[i]);
printf("\n");
}
return 1;
}```

Followed by: