题解 | #名字的漂亮度#

名字的漂亮度

http://www.nowcoder.com/practice/02cb8d3597cf416d9f6ae1b9ddc4fde3

Python 代码实现:

def calculate_weight(string:str):
    weight = 0
    count_dict = {}
    for i in string:
        if i not in count_dict:
            count_dict[i] = 1
        else:
            count_dict[i] += 1
    a = []
    for _, value in count_dict.items():
        a.append(value)
    wei = 26
    for j in sorted(a,reverse=True):
        weight += j * wei
        wei -= 1
    return weight
if __name__ == '__main__':
    while True:
        try:
            n = int(input())
            for i in range(n):
                res = calculate_weight(input())
                print(res)
        except:
            break
全部评论

相关推荐

04-14 20:10
已编辑
门头沟学院 Java
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客企业服务