注意初始化和数组置零
#include<bits/stdc++.h>
using namespace std;
bool cmp(int a, int b)
{
return a > b;
}
int main()
{
int n;
scanf("%d", &n);
for(int j = 0; j < n; j++)
{
string str;
cin >> str;
int len = str.length();
int times[26] = {0};
for(int i = 0; i < len; i++)
{
times[str[i]-'a'] ++;
}
sort(times, times+26, cmp);
int score = 0;
for(int i = 0; i < 26; i++)
{
score += times[i] * (26-i);
}
printf("%d\n", score);
}
}