题目链接http://poj.org/problem?id=1521
#include <queue>
#include <iostream>
#include <cstdlib>
#include <cstdio>
#include <algorithm>
#include <string>
using namespace std;
int cmp( const int &a, const int &b )
{
if( a > b )
return 1;
else
return 0;
}
int main()
{
string line;
int a,b,before,after;
while(1)
{
getline(cin,line);
if(line=="END")break;
int l=line.length();
after = 0;
sort(line.begin(),line.end());
char c=line[0];
int times=0,j=0;
int dep[256]={0};
for(int i=0;i<l;i++)//有几个A,几个B,几个C。。。
{
if(line[i]==c)
times++;
else
{
dep[j]=times;
j++;
c=line[i];
times=1;
}
}
dep[j]=times;
sort(dep,dep+j+1,cmp);
before = l * 8;
while(j>=1){
a = dep[j];
b = dep[j-1];
after += (a+b);
dep[--j] = a + b;
sort(dep,dep+j+1,cmp);
}
if(!after) after = l;
printf("%d %d %.1f\n",before,after,before*1.0/after);
}
return 0;
}