题解 | 名字的漂亮度

def bea_word(w):
    w_dict = {}
    for char in w:
        if char in w_dict:
            w_dict[char] += 1
        elif char not in w_dict:
            w_dict[char] = 1

    sorted_w_dict = sorted(w_dict.items(),
                           key=lambda x: x[1], reverse=True)
    length = 0
    for i in range(len(sorted_w_dict)):
        length += int(sorted_w_dict[i][1])*(26-i)

    return length
n = int(input())
for i in range(n):
    print(bea_word(input()))


全部评论

相关推荐

自由水:笑死了,敢这么面试不敢让别人说
点赞 评论 收藏
分享
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务