</pre><pre name="code" class="cpp">坑在只有一个字符的时候 #include<iostream> #include<cstdio> #include<cstring> #include<algorithm> #include<queue> using namespace std; #define maxn 1005 #define inf 0x3f3f3f3f int main() { char s[maxn]; int a[maxn]; freopen("in.txt","r",stdin); while(gets(s)){ if(!strcmp(s,"END"))break; int m=0; int sum=0; m=strlen(s); priority_queue<int>q; memset(a,0,sizeof a); for(int i=0;i<m;i++){ if(s[i]>='A'&&s[i]<='Z') a[s[i]-'A'+1]++; else a[0]++; } for(int i=0;i<=26;i++) if(a[i]>0)q.push(-a[i]); if(q.size()==1)sum+=-(q.top()); else{ while(q.size()>1){ int a=-q.top(); q.pop(); int b=-q.top(); q.pop(); sum+=a+b; q.push(-(a+b)); } } printf("%d %d %.1f\n",m*8,sum,1.0*m*8/sum); } }