#include<bits/stdc++.h>usingnamespacestd;stringlower(strings){for(inti=0;i<s.length();i++){if(s[i]>='A'&&s[i]<='Z'){s[i]+=32;}}returns;}boolcmp(inta,intb){returna>b;}intmain(){ios::sync_with_stdio(false);strings;cin>>s;cin.get();s=lower(s);intP=26;longlongintsum=0;int*arry=newint[26];for(inti=0;i<26;i++){arry[i]=0;}//let us solve it !!!!!!for(inti=0;i<s.length();++i){arry[s[i]-'a']++;}sort(arry,arry+26,cmp);for(inti=0;i<26;i++){if(arry[i]==0)break;sum+=((P--)*arry[i]);}cout<<sum;}
一个很笨的原始方法, 供大家参考!