题解 | 名字的漂亮度
名字的漂亮度
https://www.nowcoder.com/practice/02cb8d3597cf416d9f6ae1b9ddc4fde3
T = int(input())
s_list = []
for i in range(T):
s_list.append(input())
def count (c): # 建立函数,将每一个字符串的字符频率写入字典
count_dict = {}
for i in c:
if i in count_dict:
count_dict[i] += 1
else:
count_dict[i] = 1
return count_dict
for i in s_list: # 循环所有字符串,用sorted()按照value大小从高到低排序,输出漂亮度
num = 26
sum = 0
count_dict = count(i)
new_count_dict = sorted(count_dict.items(), key = lambda x : x[1], reverse = True)
for j, m in new_count_dict:
sum += m * num
num -= 1
print(sum)

