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

拜求大神指点一下为什么一直wa……

Posted by pojwyj at 2012-07-04 10:33:26 on Problem 1056
#include<iostream>
#include<string.h>
using namespace std;
struct Trinode
{
        bool isend;
        Trinode *next[2];
        Trinode()
        {
            isend=0;
            memset(next,0,sizeof(next));
        }
};

bool isable;
void insert(char*s)
{
    Trinode *temp=root;
    int i=0,nextpos;
    while(s[i])
    {
        nextpos=s[i]-'0';
        if(temp->next[nextpos]==0)
        {
            temp->next[nextpos]=new Trinode;
            temp=temp->next[nextpos];
        }
        else
        {
                temp=temp->next[nextpos];
                if(temp->isend) isable=0;
        }

        i++;
    }
    temp->isend=1;
}



int main()
{
    char s[15];
    Trinode *root=new Trinode;
    int i=0;
    while(cin>>s)
    {
        i++;
        isable=1;
        insert(s);
        while(cin>>s)
        {
            if(strcmp(s,"9")==0) break;
            if(!isable)  continue;
            insert(s);
        }
        if(isable)
            cout<<"Set "<<i<<" is immediately decodable"<<endl;
        else
            cout<<"Set "<<i<<" is not immediately decodable"<<endl;
    }
    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