题解 | #名字的漂亮度#

名字的漂亮度

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

思路:先去重,然后count,倒叙排列每个字母个数的列表,然后与对应的value相乘再相加 while True: try: n = int(input()) word = [] for _ in range(n): word.append(input()) #print(word) value = [26,25,24,23,22,21,20,19,18,17,16,15,14,13,12,11,10,9,8,7,6,5,4,3,2,1] for i in range(n): a = list(set(word[i])) #print(a) num = [] #[z,h,a,n,g,s] for j in range(len(a)): num.append(word[i].count(a[j])) num = sorted(num, reverse=True) #print(num) sum = 0 for k in range(len(num)): sum += num[k]*value[k] print(sum) except: break

全部评论

相关推荐

评论
点赞
收藏
分享
牛客网
牛客企业服务