POJ 1056

#include <iostream>
#include <string>
#define MAXN 50
using namespace std; struct node
{
node * l;
node * r;
bool boo;
node()
{
l = NULL;
r = NULL;
boo = false;
}
}; bool ans; int _index; node res[*MAXN+]; node * insert(node * root,string s,int index,int len)
{
if(s[index] == '')
{
if(root->l == NULL)
{
root->l = &res[_index ++];
root->l->boo = false;
root->l->l = root->l->r = NULL;
if(index == len-)
{
root->l->boo = true;
return root;
}
}
else
{
if(index == len-)
{
ans = false;
return root;
}
if(root->l->boo == true)
{
ans = false;
return root;
}
} root->l = insert(root->l,s,index+,len);
return root;
}
else
{
if(root->r == NULL)
{
root->r = &res[_index ++];
root->r->boo = false;
root->r->l = root->r->r = NULL;
if(index == len-)
{
root->r->boo = true;
return root;
}
}
else
{
if(index == len-)
{
ans = false;
return root;
}
if(root->r->boo == true)
{
ans = false;
return root;
}
}
root->r = insert(root->r,s,index+,len);
return root;
}
} int main()
{
//freopen("acm.acm","r",stdin);
string s;
int time = ;
while(cin>>s)
{
_index = ;
ans = true;
node * root = &res[_index ++];
root->boo = false;
root->l = root->r = NULL;
if(ans)
{
root = insert(root,s,,s.length());
}
while(cin>>s)
{
if(s == "")
{
break;
}
if(ans)
{
root = insert(root,s,,s.length());
}
}
cout<<"Set "<<++ time;
if(ans == false)
{
cout<<" is not immediately decodable"<<endl;
}
else
{
cout<<" is immediately decodable"<<endl;
}
}
}

关注我的公众号,当然,如果你对Java, Scala, Python等技术经验,以及编程日记,感兴趣的话。

POJ 1056

技术网站地址: vmfor.com

上一篇:蓝书2.3 Trie字典树


下一篇:华为测试大牛Python+Django接口自动化怎么写的?