Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  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:

Post your reply here:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator