题解 | #名字的漂亮度#

名字的漂亮度

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

n = int(input())

for i in range(n):
    s = input()

    score = 0
    l1 = []
    l2 = []

    se = list(set(s))
    ns = sorted(se, key=lambda c: -s.count(c))  # decs order

    for c in ns:
        l1.append(s.count(c))

    for i in range(26): # full list of weight
        l2.append(26-i)

    for j in range(len(se)):
        score += l2[j] * l1[j]

    print(score)

全部评论

相关推荐

什么时候才能有offer啊_:十年前我还在刺激战场研究跳伞的底层原理呢
投递牛客等公司
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客企业服务