644 - Immediate Decodability未通过

//未通过!

#include <stdio.h>
#include <string.h>

char codes[10][15];
int n;

int check(int j)
{
	for(int i=j+1;i<n;i++)
	{
		int k;
		for(k=0;codes[i][k] && codes[j][k]==codes[i][k];k++);
		if(codes[i][k]=='\0')
			return 1;
	}
	return 0;
}

int main()
{
	
	int cas=0;
	n=0;
	while(scanf("%s",codes[n])&&strcmp(codes[n],"9"))
	{
		n++;
		cas++;
		while(scanf("%s",codes[n])&&strcmp(codes[n],"9"))
		{
			n++;
		}
		int i;
		for(i=0;i<n-1;i++)
		{
			if(check(i))
			{
				printf("Set %d is not immediately decodable\n",cas);
				break;
			}
		}
		if(i==n-1)
			printf("Set %d is immediately decodable\n",cas);
	}
return 0;
}


你可能感兴趣的:(644 - Immediate Decodability未通过)