資源簡介
文本: a b c a c a d b a c d a b a a c b a b a 傳統(tǒng)表示方法:a: 00, b: 01, c: 10, d: 11 傳統(tǒng)表示未壓縮時: 0001100010001101001011001000001001001000 統(tǒng)計次數:a:9, b:5, c:4, d:2 前綴碼表示:a: 0, b: 10, c:110, d:111 壓縮后: 0101100110011110011011101000110100100
代碼片段和文件信息
#include
#include
#include
using?namespace?std;
typedef?struct?SC
{
char?ss[100];//所有字符串
char?s[100];//不重復的字符串
int?si[100];//每個字符的總數
int?per[100];
int?i;//字符數
string?str[100];//code
int?count;//總數
double?CountPer;//壓縮率
int?mixlen;//編碼的最長長度
}SC;
void?MaxLen(SC?&s);
string?OutHufCode(char?cSC?s);
double?compress(SC?s);
void?HufumanCode(SC?&s);
void?InitSC(SC?&s);
int?Search(SC?schar?c);
void?SortSC(SC?&s);
int?main()
{
ifstream?fin(“Input.txt“);
ofstream?fout(“Output.txt“);
char?cc1;
SC?s;InitSC(s);
int?i=0;
while(!fin.eof())
{
fin>>c;
if(fin.get()==‘\n‘)
break;
s.ss[s.count++]=c;
if(Search(sc)==-1)
{
s.s[s.i]=c;
s.si[s.i]++;
s.i++;
}
else
{
s.si[Search(sc)]++;
}
}
for(i=0;i {
cout< }
SortSC(s);
cout<<“**********\n“;
for(i=0;i {
cout< }
cout<<“**********\n“;
for(i=0;i
- 上一篇:計算機組成原理cop2000乘除法課程設計
- 下一篇:二叉排序樹與平衡二叉樹的實現
評論
共有 條評論