| ||||||||||
| 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 | |||||||||
tier树做得,不晓得为什么一直WA。。请高人指教#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: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator