一、题目
二、代码
import java.util.Arrays;
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
while (in.hasNext()) {
int num = in.nextInt();
String[] strs = new String[num];
for (int i = 0; i < num; i++) {
strs[i] = in.next();
}
for (int i = 0; i < strs.length; i++) {
String temp = strs[i];
int[] count = new int[26];
for (int j = 0; j < temp.length(); j++) {
char c = temp.charAt(j);
if (c >= 'a' && c <='z') {
count[c-'a']++;
} else if (c >= 'A' && c <='Z') {
count[c-'A']++;
}
}
Arrays.sort(count);
int res = 0;
for (int j = 0; j < count.length; j++) {
int beauty = j+1;
res += count[j] * beauty;
}
System.out.println(res);
}
}
}
}