644

#include <iostream>
#include <cstdio>
#include <cstring>
#include <string>

using namespace std;

struct node{
	bool end;
	node *nxt[2];
	node()
	{
		end=false;
		for(int i=0;i<2;i++)
		nxt[i]=NULL;
	}
}*root;
int main()
{
	string str,s;
	int id;
	node *cur,*tmp;
	int kase=1;
	while(cin>>str)
	{
		bool decodable=1;
		root=new node();
		cur=root;
		int i;
		for( i=0;i<str.size()-1;i++)
		{
			id=str[i]-'0';
			if(cur->nxt[id]==NULL)
			{
				cur->nxt[id]=new node();
			}
			cur=cur->nxt[id];
		}
		id=str[i]-'0';
		if(cur->nxt[id]==NULL)
		{
			cur->nxt[id]=new node();
		}
		cur=cur->nxt[id];
		cur->end=1;
		while(cin>>s)
		{
			if(s=="9")
			break;
			if(decodable==0)
			continue;
			tmp=root;
			int j;
			for( j=0;j<s.size()-1;j++)
			{
				id=s[j]-'0';
				if(tmp->nxt[id]==NULL)
					tmp->nxt[id]=new node();
				tmp=tmp->nxt[id];
				if(tmp->end==1)
				{
					decodable=0;
					j=s.size();
				}
			}
			id=s[j]-'0';
			if(tmp->nxt[id]==NULL)
				tmp->nxt[id]=new node();
			else
				decodable=0;
			tmp=tmp->nxt[id];
			tmp->end=1;
		}
		if(decodable)
		cout<<"Set "<<kase++<<" is immediately decodable\n";
		else
		cout<<"Set "<<kase++<<" is not immediately decodable\n";
	}
	return 0;
}

 

Leave a Reply

Your email address will not be published. Required fields are marked *