题解 | #名字的漂亮度#

名字的漂亮度

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

while 1:
    try:
        n = int(input())
        l = []
        nums = []
        values = list(reversed(range(1,27)))
        for i in range(n):
            l.append(input())
            char = []
            nums = []
            for j in range(len(l[i])):
                if l[i][j] not in char:
                    char.append(l[i][j])
                    nums.append(1)
                else:
                    nums[char.index(l[i][j])] += 1
            new_word = ''
            for k in range(len(char)):
                new_word += char[nums.index(max(nums))]
                nums[nums.index(max(nums))] = 0
            key_values = {}
            score = 0
            for a in range(len(new_word)):
                key_values[new_word[a]] = values[a]
            for j in l[i]:
                score += key_values[j]
            print(score)
    except:
        break
全部评论

相关推荐

走不到的路就这样算了吗:大佬硬气
点赞 评论 收藏
分享
评论
1
收藏
分享
牛客网
牛客企业服务