编程介的小学生 2017-10-27 14:53 采纳率: 20.5%
浏览 857
已采纳

DEHUFF

Description

A certain data compression technique involves creating a table of variable-length binary codes where one or more binary digits are used to represent a single letter of an alphabet. Usually, letters that occur most frequently in words
generated using this alphabet will have shorter binary codes than those used less frequently. For example, in an alphabet consisting of the letters A through Z, in general the letter E appears in more words than the letter Q;
therefore it would be expected that E would have a shorter binary code than does Q.
Given a sample string using at least one of each letter in an alphabet, along with the entire binary encoding of that sample string, you should be able to generate at least one binary code table for each letter in the alphabet. For
example, consider the sample string: "CAB" which contains each letter of the alphabet {A,B,C}. If the binary encoding of "CAB" is "01011" then the (only) binary code table is:
C = 0
A = 10
B = 11
The binary codes for each character are prefix codes in that no code in the set can be the initial binary string for any other code (so A = 01, B = 011 would not be allowed). For this problem, you will write a program that determines
binary code tables for sample strings and their binary encodings. If there is a single binary code table solution, then you will print it out (sorted). If more than one binary code table can be generated from the given set of data, you
will print "MULTIPLE TABLES". Note: For a given alphabet, the entire code space will be used; that is, there will be no unused codes.
Input

Input consists of a single line consisting of an integer value N representing the number of datasets that follow. Each dataset consists of two lines. The first line is the sample string that contains at least one of each letter (or space) in
the alphabet. The second line is the binary encoding of the sample string. Note: Sample strings may only contain upper case letters and spaces.
Output

For each dataset, print a line that identifies the dataset in the format: "DATASET #n" where n is the dataset number (1 through N). If more than one binary code table can be generated to represent the alphabet, print "MULTIPLE TABLES" on a new line and move onto the next dataset. If only one binary code table can be generated, for each character in the alphabet, display the letter, a space, and equal sign (=), a space and the binary code for that letter.
Display the table in order sorted by the ASCII value of each character of the alphabet.
Sample Input

3
CAB
01011
HELLO WORLD
111011011110111101111100111111111111011111101111010
ABCDEFGHI
010110111011110111110111111011111110001011111111
Sample Output

DATASET #1
A = 10
B = 11
C = 0
DATASET #2
= 0
D = 10
E = 110
H = 1110
L = 11110
O = 111110
R = 1111110
W = 1111111
DATASET #3
MULTIPLE TABLES

  • 写回答

1条回答 默认 最新

  • threenewbee 2017-11-14 10:43
    关注
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥50 导入文件到网吧的电脑并且在重启之后不会被恢复
  • ¥15 (希望可以解决问题)ma和mb文件无法正常打开,打开后是空白,但是有正常内存占用,但可以在打开Maya应用程序后打开场景ma和mb格式。
  • ¥15 绘制多分类任务的roc曲线时只画出了一类的roc,其它的auc显示为nan
  • ¥20 ML307A在使用AT命令连接EMQX平台的MQTT时被拒绝
  • ¥20 腾讯企业邮箱邮件可以恢复么
  • ¥15 有人知道怎么将自己的迁移策略布到edgecloudsim上使用吗?
  • ¥15 错误 LNK2001 无法解析的外部符号
  • ¥50 安装pyaudiokits失败
  • ¥15 计组这些题应该咋做呀
  • ¥60 更换迈创SOL6M4AE卡的时候,驱动要重新装才能使用,怎么解决?