题解 | #名字的漂亮度#
名字的漂亮度
http://www.nowcoder.com/practice/02cb8d3597cf416d9f6ae1b9ddc4fde3
使用字典来解决
while True:
try:
n = input()
except:
break
if n.isnumeric():
...
else:
dic = {}
for c in n:
if dic.get(c):
dic[c] += 1
else:
dic[c] = 1
num_list = sorted(dic.values(), reverse=True) # 对字典的值进行排序,从大到小
beautiful = 26
sum_beau = 0
for num in num_list:
sum_beau += num * beautiful
beautiful -= 1 # 漂亮值每次减少1
print(sum_beau)