题目描述
通常要求根据给定的编码本对密文进行解码。现已给定相应字符的哈夫曼编码,要求根据编码对密文进行解码。(建立哈夫曼树以及编码、主函数等都已经给出,你只需要填写译码函数void ccode(haffnode hafftree[],int n)即可。
输入
根据哈夫曼树编码表,针对字符串做好的编码结果。
输出
对每一行需要解码的串,进行解码,并输出解码后的结果。
#include<bits/stdc++.h>
using namespace std;
int t = 0;
void haf(string s){
if(s=="0001") cout<<"a";
if(s=="10") cout<<"b";
if(s=="1110") cout<<"c";
if(s=="1111") cout<<"d";
if(s=="110") cout<<"e";
if(s=="01") cout<<"f";
if(s=="0000") cout<<"g";
if(s=="001") cout<<"h";
}
int main(){
string a, b;
cin>>a;
while(t<a.length()){
b += a[t];
if(a[t]!=b[0]||b.length()==4){
haf(b);
b.clear();
}
t++;
}
}