UVA 644 Immediate Decodability (寻找前缀)

分析:直接暴力求解,尝试每个是不是另外每个的前缀便可


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

char sb[105][105];
int judge = 0;

int main()
{
    int t = 0;
    int tt = 1;
    while (gets(sb[t ++]) != NULL)
    {
	if (sb[t - 1][0] == '9')
	{
	    for (int i = 0; i < t; i ++)
		for (int j = i + 1; j < t; j ++)
		{
		    int leni = strlen(sb[i]);
		    int lenj = strlen(sb[j]);
		    int len = leni > lenj? lenj : leni;
		    if (strncmp(sb[i], sb[j] , len) == 0)//strcnmp
		    {
			judge = 1;
			break;
		    }
		}
	    if (judge)
		printf("Set %d is not immediately decodable\n", tt ++);
	    else
		printf("Set %d is immediately decodable\n", tt ++);
	    judge = 0;
	    t = 0;
	    memset(sb, 0, sizeof(sb));
	}
    }
    return 0;
}

你可能感兴趣的:(immediate,uva,de,644)