请教一道题!用PASCAL语言做~~

来源:百度知道 编辑:UC知道 时间:2024/05/27 12:33:36
给定一篇文章,文章由26个字母(不区分大小写)、逗号、句号、空格组成,文章的字符数不超过10000,请构造这篇文章的哈夫曼树,将这篇文章编成哈夫曼编码,保存到输出文件,然后以上面的输出文件为输入文件,破译该哈夫曼编码文件,将破译后的结果保存至另一输出文本。

{$ r-,q-,s-} {guang yi ha fu man}
uses crt;
type
codetype=record
code:string;
len:longint;
end;
tree=^rec;
rec=record
cd:array[1..8] of tree;
W:longint;
c:char;
end;
var
n,m,o:longint;
st:string;
hufftree:tree;
s:codetype;
huffcode:array['a'..'z'] of codetype;
forest:array['a'..'z'] of tree;
trees:array[1..100] of tree;
procedure init;
var i:longint;ch:char;
begin
write('I am ready:');readln(st);
write('How many codes do you need:');readln(n);
for i:=1 to length(st) do begin
if forest[st[i]]=NIL then begin new(forest[st[i]]);forest[st[i]]^.W:=0;forest[st[i]]^.c:=st[i];end;
inc(forest[st[i]]^.W);end;
for i:= 1 to 100 do
b