题解 | #名字的漂亮度#把名字中的字母出现次数按从大到小排序,依次对应漂亮度26,25,24...
名字的漂亮度
http://www.nowcoder.com/practice/02cb8d3597cf416d9f6ae1b9ddc4fde3
while True:
try:
n = int(input())
for i in range(n):
each_name = input()
beauty = 0
# 字典放名字中每种字母对应出现到次数
dict1 = {}
for c in each_name:
dict1[c] = each_name.count(c)
# 每种字母的出现次数从大到小排列
times_list = sorted(dict1.values(), reverse=True)
# 次数从大到小以此乘以26,25,24...
for j in range(len(times_list)):
beauty += (26 - j) * times_list[j]
print(beauty)
except:
break
try:
n = int(input())
for i in range(n):
each_name = input()
beauty = 0
# 字典放名字中每种字母对应出现到次数
dict1 = {}
for c in each_name:
dict1[c] = each_name.count(c)
# 每种字母的出现次数从大到小排列
times_list = sorted(dict1.values(), reverse=True)
# 次数从大到小以此乘以26,25,24...
for j in range(len(times_list)):
beauty += (26 - j) * times_list[j]
print(beauty)
except:
break