add Compression ratio

This commit is contained in:
xice
2018-05-21 16:52:38 +08:00
parent 598a3e5f1d
commit 73e7489317

View File

@@ -170,8 +170,11 @@ int main(){
Huffman Huffman1(a);
char b[800]={'\0'};
char c[100]={'\0'};
int nb = -1,nc = -1;
Huffman1.Encode(a,b);
Huffman1.Decode(b,c);
while(b[++nb] != '\0');
while(c[++nc] != '\0');
system(CLEAR);
cout <<"+----------------------------+"<<endl;
cout <<"| 哈弗曼树实现 |"<<endl;
@@ -185,6 +188,12 @@ int main(){
cout <<"|"<<setw(28)<<setiosflags(ios::left)<<c<<"|"<<endl;
cout <<"| 按Enter进入菜单 |"<<endl;
cout <<"+----------------------------+"<<endl;
cout <<"编码前长度"<<endl;
cout << nc*8 << endl;
cout << "编码后长度" <<endl;
cout << nb << endl;
cout << "压缩率" << endl;
cout << (double)nb/(nc*8) << endl;
cin.get();cin.get();
int chouse;
goback:;