哈夫曼解碼
1000(ms)
10000(kb)
1570 / 3422
通常要求根據給定的編碼本對密文進行解碼。現已給定相應字元的哈夫曼編碼,要求根據編碼對密文進行解碼。(建立哈夫曼樹以及編碼、主函式等都已經給出,你只需要填寫解碼函式void ccode(haffnode hafftree,int n)即可。
const int maxvalue=100;
const int maxbit=100;
const int maxn=100;
#include "iostream"
#include "stdio.h"
#include "stdlib.h"
using namespace std;
struct haffnode
; struct code
; void haffman(int weight,char text,int n,haffnode hafftree)
else
hafftree[i].parent=0;
hafftree[i].flag=0;
hafftree[i].leftchild=-1;
hafftree[i].rightchild=-1;
} for(i=0;i< n-1;i++)
else if(hafftree[j].weight< m2&&hafftree[j].flag==0)
} hafftree[x1].parent=n+i;
hafftree[x2].parent=n+i;
hafftree[x1].flag=1;
hafftree[x2].flag=1;
hafftree[n+i].weight=hafftree[x1].weight+hafftree[x2].weight;
hafftree[n+i].leftchild=x1; hafftree[n+i].rightchild=x2;
} }
void haffmancode(haffnode hafftree,int n,code haffcode)
for(j=cd.start+1;j< n;j++)
haffcode[i].bit[j]=cd.bit[j];
haffcode[i].start=cd.start;
haffcode[i].weight=cd.weight;
haffcode[i].ch=cd.ch;
} }
void ccode(haffnode hafftree,int n)
int main( )
; char text=;
haffnode myhafftree[maxvalue];
code myhaffcode[maxvalue];
haffman(weight,text,n,myhafftree);
haffmancode(myhafftree,n,myhaffcode);
ccode(myhafftree,n);
return 0;
} 輸入
根據哈夫曼樹編碼表,針對字串做好的編碼結果。輸出
對每一行需要解碼的串,進行解碼,並輸出解碼後的結果。樣例輸入
000100011011101110樣例輸出
aabcc
就是把他給的**瞎改就a了;
const int maxvalue=100;
const int maxbit=100;
const int maxn=100;
#include "iostream"
#include "stdio.h"
#include "string.h"
#include "stdlib.h"
using namespace std;
struct haffnode
;struct code
; void haffman(int weight,char text,int n,haffnode hafftree)
else
hafftree[i].parent=0;
hafftree[i].flag=0;
hafftree[i].leftchild=-1;
hafftree[i].rightchild=-1;
} for(i=0;i< n-1;i++)
else if(hafftree[j].weight< m2&&hafftree[j].flag==0) }
hafftree[x1].parent=n+i;
hafftree[x2].parent=n+i;
hafftree[x1].flag=1;
hafftree[x2].flag=1;
hafftree[n+i].weight=hafftree[x1].weight+hafftree[x2].weight;
hafftree[n+i].leftchild=x1; hafftree[n+i].rightchild=x2;
} }
void haffmancode(haffnode hafftree,int n,code haffcode)
for(j=cd.start+1;jhaffcode[i].bit[j]=cd.bit[j];
haffcode[i].start=cd.start;
haffcode[i].weight=cd.weight;
haffcode[i].ch=cd.ch;
} }
void ccode(haffnode hafftree,int n)
j++;}}
int main( )
;char text=;
haffnode myhafftree[maxvalue];
code myhaffcode[maxvalue];
haffman(weight,text,n,myhafftree);
haffmancode(myhafftree,n,myhaffcode);
ccode(myhafftree,n);
return 0;
}
哈夫曼編碼解碼
簡單實現編碼解碼功能 列印哈夫曼樹形 該怎麼做呢 求教!實現初始化,建立huffman樹,並完成字元的編碼 之前解碼用for迴圈不能夠重新復位遍歷 while更好用 include stdio.h include string.h define n 10 待編碼字元的個數,即樹中葉結點的最大個數 d...
哈夫曼編碼與解碼
include include include include define maxnum 60typedef struct huffnode typedef struct huffcode huffnode ht maxnum 2 存放哈夫曼樹 huffcode hcd maxnum 存放ht陣列...
哈夫曼編碼和解碼
試題描述 輸入為 一段英文或中文的文章 原文 對輸入的文章構造哈夫曼樹,生成對應的編碼,輸出為 原文所對應的編碼 譯文 根據已經生成的編碼表,輸入任意的譯文可以得到對應的原文。要求有執行結果截圖。include using namespace std typedef struct point huf...