题解 | #名字的漂亮度#

名字的漂亮度

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

n = int(input())        # 输入字符串的行数

# 输入n行字符串
for _ in range(n):
    str = input().lower()

    beauty = 0      # 定义漂亮度
    dic = {}        # 定义字典,用来存储字母和字母出现的次数

    # 统计每种字符出现的次数
    for letter in str:
        dic[letter] = str.count(letter)
    # 针对每种字母出现的次数从大到小排序
    sort_letter_times = sorted(dic.values(),reverse=True)

    # 遍历字母次数列表,并且用次数从大到小乘以26,25,24,23,。。。
    for k in range(len(sort_letter_times)):
        beauty += (26 - k) * sort_letter_times[k]
    
    print(beauty)

全部评论

相关推荐

牛客21331815...:像我一投就pass,根本不用焦虑泡池子
点赞 评论 收藏
分享
09-14 17:23
门头沟学院
故事和酒66:所以说副业很重要,程序员干到40岁,再怎么也赚300万了,吃吃利息也够活下去
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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