题解 | #HJ45 名字的漂亮度#
名字的漂亮度
http://www.nowcoder.com/practice/02cb8d3597cf416d9f6ae1b9ddc4fde3
Python版本
import sys
def histogram(string):
histo = {}
for c in string:
histo[c] = histo.get(c, 0) + 1
return histo
def func(string):
histo = histogram(string)
status = [(k, v) for (k, v) in histo.items()]
status.sort(key=lambda x: x[1])
length = len(status)
result = 0
for i in range(length):
result += (26-i) * status[length-1-i][1]
return result
n = int(input())
for line in sys.stdin:
content = line.strip()
result = func(content)
print(result)