• 大小: 2.44KB
    文件类型: .cpp
    金币: 1
    下载: 0 次
    发布日期: 2021-03-28
  • 语言: 其他
  • 标签: 其他  

资源简介


文本: a b c a c a d b a c d a b a a c b a b a 传统表示方法:a: 00, b: 01, c: 10, d: 11 传统表示未压缩时: 0001100010001101001011001000001001001000 统计次数: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

评论

共有 条评论