Sample Input AAAAABCD THE_CAT_IN_THE_HAT END

Output 64 13 4.9 144 51 2.8

## 思路

8位ASCII编码的位长度：即字符种类数乘8。 最佳无前缀可变长度编码的位长：即哈夫曼编码的长度sum。 精确到一个小数点的压缩比：8位ASCII编码的位长度除以最佳无前缀可变长度编码的位长，用格式化输出的转换说明来保留一位小数。

## AC代码

``````#include <iostream>
#include <sstream>
#include <map>
#include <queue>
#include <cstdio>
#define AUTHOR "HEX9CF"
using namespace std;

int main()
{
char ch;
string str;
while (cin >> str)
{
int cnt = 0;
int sum = 0;
map<char, int> mw;
priority_queue<int, vector<int>, greater<int>> pq;
if ("END" == str)
{
break;
}
stringstream ss(str);
while (ss >> ch)
{
mw[ch]++;
// cout << ch;
cnt++;
}
for (map<char, int>::iterator it = mw.begin(); it != mw.end(); it++)
{
pq.push(it->second);
// cout << it->first << " " << it->second << endl;
}
// cout << pq.top();
if(1 == pq.size()){
sum += pq.top();
}
while (pq.size() > 1)
{
int a, b, c;
a = pq.top();
pq.pop();
b = pq.top();
pq.pop();
c = a + b;
sum += c;
pq.push(c);
}
printf("%d %d %.1lf\n", cnt * 8, sum, cnt * 8 / (double)sum);
}
return 0;
}``````