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

tier树做得,不晓得为什么一直WA。。请高人指教

Posted by is5land at 2010-02-02 21:31:13 on Problem 1056
#include <iostream>
using namespace std;

struct leafage
{
	bool sign;
	leafage * branch[10];
}Leafage[100000];



int nodenum;  




bool insert(leafage * root,char * num)
{
	int len=strlen(num);
	leafage * p;
	p=root;
	int i(0);
	while(num[i])
	{

	
		if(i==len-1 && p->branch[num[i]-'0'] != NULL)
            return false;


	
		if(p->branch[num[i]-'0']== NULL)   
		{
			p->branch[num[i]-'0'] = &Leafage[nodenum];
			Leafage[nodenum].sign =false;
			memset(Leafage[nodenum].branch,NULL,sizeof(Leafage[nodenum].branch));
            nodenum++;
		}

	
		
		if(p->branch[num[i]-'0']->sign == true)
		{
			return false;
		}

		p = p->branch[num[i]-'0']; 
        i++;
	}
	p->sign = true;
    return true;
}



int main()
{
	leafage * root;
	root = &Leafage[0];
	char num[20];
	char signcmp[2]="9";
	nodenum = 1;
	bool flage =true;
	memset(Leafage[0].branch,NULL,sizeof(Leafage[nodenum].branch));
	while(cin>>num)
	{
		if(strcmp(num,signcmp)!=0)
			if(!insert(root,num))
				flage = false;
			
		if(flage && strcmp(num,signcmp)==0)
		{	
			cout<<"Set 1 is immediately decodable"<<endl;
			memset(Leafage[0].branch,NULL,sizeof(Leafage[nodenum].branch));
			root=&Leafage[nodenum++];
		}
		if(!flage && strcmp(num,signcmp)==0)
		{
			cout<<"Set 2 is not immediately decodable"<<endl;
			root=&Leafage[nodenum++];
			flage = true;
	
		}
	}

	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