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 phoenix_hjp at 2014-03-15 10:21:15 on Problem 2001
```#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
char dic[10000][20];
typedef struct node
{
int count;
struct node *next[26];
}node;
node *root=new node();
void insert(int num)
{
int len=strlen(dic[num]);
node *now=root;
node *newnode;
for(int i=0;i<len;i++)
{
if(now->next[dic[num][i]-'a']!=NULL)
{
now=now->next[dic[num][i]-'a'];
(now->count)++;
}
else
{
newnode=new node();
newnode->count=1;
for(int j=0;j<26;j++)
newnode->next[j]=NULL;
now->next[dic[num][i]-'a']=newnode;
now=newnode;
}
}
}
void search(int num)
{
int len=strlen(dic[num]);
node *now=root;
for(int i=0;i<len;i++)
{
now=now->next[dic[num][i]-'a'];
printf("%c",dic[num][i]);
if(now->count==1)
{
printf("\n");
return ;
}
}
printf("\n");
}
int main()
{
int i,j,k=0;
root->count=0;
for(i=0;i<26;i++)
root->next[i]=NULL;
while(gets(dic[k])&& dic[k][0]!='0')
{
insert(k);
k++;
}
for(i=0;i<k;i++)
{
printf("%s ",dic[i]);
search(i);
}
return 0;
}
```

Followed by: