An encoding of a set of symbols are said to being immediately decodable if no code for one symbol are the prefix of a code for Another symbol. We'll assume for this problem-all codes is in binary, that's no codes within a set of codes is the same, that E The ACH code have at least one bit and no more than ten bits, and so each set have at least, codes and no more than eight.
Examples: Assume an alphabet as has symbols {A, B, C, D}
The following code is immediately decodable:
a:01 b:10 c:0010 d:0000
It's not:
a:01 b:10 c:010 d:0000 (Note that a was a prefix of C)
Input
Write A program this accepts as input a series of groups of records from a data file. Each record in a group contains a collection of zeroes and ones representing a binary code for a different symbol. Each group was followed by a single separator The record containing a single 9; The separator records is not part of the group. Each group was independent of other groups; The codes in one group was not related to codes with any other group (so is, each group was to be processed independently).
Output
For each group, your program should determine whether the codes of that group is immediately decodable, and should print A single output line giving the group number and stating whether the group are, or is not, immediately decodable.
The Sample Input describes the examples above.
Sample Input
0010
0000
9
010
0000
9
Sample Output
Set 1 is immediately decodable
set 2 are not immediately decodable
Prefix encoding, because the data is very small direct poor to take each kind of judgment can, began to think only half, but because of judgment when there is a length of conditions, so the opposite situation is to judge or n*n times, can not N*N/2;
while (scanf ("%s", &s[sum]) ==1), the return value of scanf is the number of read-in values, so the end is 0 when no data is read. Later with EOF handed down can also ╮(╯▽╰)╭ not too dependent on someone else's code.
#include <stdio.h>
#include <string.h>
void Main ()
{char s[10][10];
int num=0,l1,l2,flag,i,j,k,sum=0,a[10];
while (scanf ("%s", &s[sum]) ==1)
{
while (scanf ("%s", &s[sum+1])
if (s[sum+1][0]== ' 9 ') break;
else ++sum;
for (i=0;i<=sum;i++)
A[i]=strlen (S[i]);
for (i=0;i<=sum;i++)
{
for (j=0;j<=sum;j++)
{flag=1;
if ((i!=j) && (A[j]>=a[i]))
{for (k=0;k<a[i];k++)
if (S[i][k]!=s[j][k]) {flag=0; break;}
}
else flag=0;
if (flag) goto there;
}
}
there:;
sum=0;
++num;
if (flag) printf ("Set%d is not immediately decodable\n", num);
else printf ("Set%d is immediately decodable\n", num);
}
}