Python 代码实现:
def calculate_weight(string:str):
weight = 0
count_dict = {}
for i in string:
if i not in count_dict:
count_dict[i] = 1
else:
count_dict[i] += 1
a = []
for _, value in count_dict.items():
a.append(value)
wei = 26
for j in sorted(a,reverse=True):
weight += j * wei
wei -= 1
return weight
if __name__ == '__main__':
while True:
try:
n = int(input())
for i in range(n):
res = calculate_weight(input())
print(res)
except:
break