UVa644 - Immediate Decodability

题目地址:点击打开链接

C++代码:

 

#include <cstdio>
#include <cstring>
int main()
{
	char s[100][100];
	char str[100];
	int cas=1;
	int n;
	int i,j,k;
	while(scanf("%s",str)!=EOF)
	{
		n=0;
		while (str[0]!='9')
		{
			strcpy(s[n++],str);
			scanf("%s",str);
		}
		int flag=1;
		for(i=0;i<n-1;++i)
		{
			for(j=i+1;j<n;++j)
			{
				int len=strlen(s[i])<strlen(s[j])?strlen(s[i]):strlen(s[j]);
				for(k=0;k<len&&s[i][k]==s[j][k];++k);
				if(k==len)
				{
					flag=0;
					goto loop;
				}
			}
		}
loop:
		if(flag==1)
			printf("Set %d is immediately decodable\n",cas++);
		else
			printf("Set %d is not immediately decodable\n",cas++);
	}
	return 0;
}


 

 

posted @ 2013-08-07 18:18  jlins  阅读(239)  评论(0编辑  收藏  举报