#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
//谢谢博友文章
int main()
{
int js=0;
while(1)
{
js++;
vector<string> a;
while(1)
{
string t;
cin>>t;
if(cin.eof()==1)
{
break;
}
if(t=="9")
{
break;
}
a.push_back(t);
}
if(cin.eof()==1)
{
break;
}
sort(a.begin(),a.end());
int flag=0;
for(int i=0;i<a.size()-1;i++)
{
if(a[i].size()<a[i+1].size())
{
if(a[i]==a[i+1].substr(0,a[i].size()))
{
flag=1;
break;
}
}
}
if(flag==0)
{
cout<<"Set "<<js<<" is immediately decodable"<<endl;
}else
{
cout<<"Set "<<js<<" is not immediately decodable"<<endl;
}
}
return 0;
}
#include <iostream>
#include <vector>
#include <string>
#include <cstring>
using namespace std;
//trie
struct nod{
int a0;
int a1;
}da[1000000];
vector<string> ve;
int js;
int tag;
int main()
{
js=1;
while(1)
{
while(1)
{
string s;
cin>>s;
if(cin.eof()==1)
{
return 0;
}
if(s=="9")
{
int jg=0;
for(int o=0;o<ve.size();o++)
{
int wz=1;
string s=ve[o];
for(int i=0;i<s.size();i++)
{
if(s[i]=='0')
{
if(da[wz].a0==0)
{
js++;
da[wz].a0=js;
}
wz=da[wz].a0;
}else if(s[i]=='1')
{
if(da[wz].a1==0)
{
js++;
da[wz].a1=js;
}
wz=da[wz].a1;
}
}
if(da[wz].a0!=0 || da[wz].a1!=0)
{
jg=1;
break;
}
}
tag++;
if(jg==0)
{
cout<<"Set "<<tag<<" is immediately decodable\n";
}else
{
cout<<"Set "<<tag<<" is not immediately decodable\n";
}
js=1;
ve.clear();
memset(da,0,sizeof(da));
break;
}
int wz=1;
for(int i=0;i<s.size();i++)
{
if(s[i]=='0')
{
if(da[wz].a0==0)
{
js++;
da[wz].a0=js;
}
wz=da[wz].a0;
}else if(s[i]=='1')
{
if(da[wz].a1==0)
{
js++;
da[wz].a1=js;
}
wz=da[wz].a1;
}
}
ve.push_back(s);
}
}
}