/*
* 解题思路:
* 题意是: 判断输入的多组数据中,有无哪组数据是另一组数据的前缀、相应输出结果即可
* 开始一直WA、是没有控制好假如一个字符串有多组匹配字符串,要控制只输出一次( 怪自己粗心 )!
*/
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#define A 100
int cmp( const void * _a , const void * _b )
{
char *a = ( char *)_a;
char *b = ( char *)_b;
if( strlen( a ) < strlen( b ) ) return 1;
if( strlen( a ) > strlen( b ) ) return -1;
return strcmp( a , b );
}
int main( )
{
int p,q;
int i,j,k;
int flag,total,vis;
char ss[ A ][ A ];
char c;
c = ‘0‘;
total = 1;
while( c != EOF )
{
p = q = vis = 0;
while( ( c = getchar( ) ) != ‘9‘ && c != EOF )
{
vis =1;
if( c == ‘0‘ || c == ‘1‘ ) ss[ p ][ q++ ] = c;
else
{
ss[ p ][ q ] = ‘\0‘;
p++;
q = 0;
}
}
if( c!=EOF )
c = getchar( );
if( vis )
{
qsort( ss , p , sizeof( ss[ 0 ] ) , cmp );
vis = 0;
for( i=0;i<p;i++ )
{
for( j=p-1;strlen( ss[ i ] ) > strlen( ss[ j ] ) ; j-- )
{
flag = 1;
for( k=0;k<strlen( ss[ j ] ) ;k++ )
if( ss[ i ][ k ] != ss[ j ][ k ] )
{
flag = 0;
break;
}
if( flag )
{
vis = 1;
printf("Set %d is not immediately decodable\n",total++);
break;
}
}
if( vis ) break;
}
if( !vis ) printf("Set %d is immediately decodable\n",total++ );
}
}
return 0;
}