| ||||||||||
| Online Judge | Problem Set | Authors | Online Contests | User | ||||||
|---|---|---|---|---|---|---|---|---|---|---|
| Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest | |||||||||
到底是怎么错了,求大牛指教#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: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator