文章
2
粉丝
305
获赞
2
访问
17.2k
#include<bits/stdc++.h>
using namespace std;
int main(){
string s;
while(cin>>s){
if(s=="END") break;
priority_queue<int,vector<int>,greater<int>> q;
int a[128] = {0};
int sum = 0;
int weishu = 8*s.size();
double ratio;
for(int i=0;i<s.size();i++){
a[s[i]]++;
}
for(int i=0;i<=127;i++){
if(a[i]>0)
q.push(a[i]);
}
if(q.size()==1){
sum = s.size();
}
else{
while(q.size()>1){
int num1 = q.top();
q.pop();
int num2 = q.top();
q.pop();
sum += num1 + num2;
q.push(num1+num2);
}
}
ratio = double(weishu)/double(sum);
printf("%d %d %.1lf\n",weishu,sum,ratio);
}
return 0;
}
登录后发布评论
暂无评论,来抢沙发