判定唯一可译码 2
LZw 编码 3
算数编码 一 判定唯一可译码 1.任务说明 输入:任意的一个码(即已知码字个数及每个具体的码字) 输出:判决结果(是/不是) 输入文件:in1
tx t,含至少2 组码,每组的结尾为”$”符 输出文件:ou t1
tx t,对每组码的判断结果 说明:为了简化设计,可以假定码字为0,1 串 2.问题分析、实现原理、流程图 参考算法伪代码: For all ,ijW WC do if iW 是jW 的前缀 then 将相应的后缀作为一个尾随后缀放入集合0F 中 End if End for Loop For all iWC do For all jnWF do if iW 是jW 的前缀 then 将相应的后缀作为一个尾随后缀放入集合1nF 中 Else if jW 是iW 的前缀 then 将相应的后缀作为一个尾随后缀放入集合1nF 中 End if End for End for iiFF If ,iiWF WC then Return false Else if F 中未出现新的元素 then Return true End if //能走到这里,说明F 中有新的元素出现,需继续 End loop 3.实现源码 #include #include using namespace std; struct strings { char *string; struct strings *next; }; struct strings Fstr, *Fh, *FP; //输出当前集合 void outputstr(strings *str) { do { coutnext; if(
strcmp(st_string->string,code)) return 0; } return 1; } //判断两个码字是否一个是另