题解 | #名字的漂亮度#

名字的漂亮度

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

while True:
    try:
        line = int(input())
        for l in range(line):
            string = input()
            dic = {}
            max, base = 0, 26
            for c in string:
                dic[c] = dic.get(c,0) + 1
            # print(dic)
            p_dic = dict(sorted(dic.items(), key=lambda item: item[1],reverse=True))
            # print(p_dic)
            for v in p_dic.values():
                max += v*base
                base -= 1
            print(max)
    except:
        break

全部评论

相关推荐

头像
不愿透露姓名的神秘牛友
03-20 10:18
点赞 评论 收藏
转发
点赞 收藏 评论
分享
牛客网
牛客企业服务