题解 | #名字的漂亮度#
名字的漂亮度
https://www.nowcoder.com/practice/02cb8d3597cf416d9f6ae1b9ddc4fde3
#首先定义函数,在函数中将字符串里各个字母以及出现的次数加入到字典中,
#然后逆向排序,再依照排序后的结果依次乘以对应的数字,求和
def piaoliang(str1):
count_dict={}
sum=0
kind=26
for i in str1:
if i not in count_dict:
count_dict[i]=1
else:
count_dict[i]=count_dict[i]+1
count_list=sorted(count_dict.items(),key=lambda x:-x[1])
for i in count_list:
sum=sum+i[1]*kind
kind=kind-1
print(sum)
N=int(input())
while N>0:
try:
str1=input()
piaoliang(str1)
N=N-1
except:
break

