题解 | 名字的漂亮度
list2=[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] n=int(input()) for i in range(n): listt=input() listcopy= {} for i in listt: if i not in listcopy: listcopy[i]=1 else: listcopy[i] = listcopy[i]+1 x=list(listcopy.values()) x.sort(reverse=True) result_s=0 for i in range(len(x)): s=x[i]*list2[i] result_s=result_s+s print(result_s) 次数排序用到了字典。 字典不能通过位置索引,只能根据键索引。