题解 | #名字的漂亮度#
名字的漂亮度
https://www.nowcoder.com/practice/02cb8d3597cf416d9f6ae1b9ddc4fde3
import java.util.*;
// 注意类名必须为 Main, 不要有任何 package xxx 信息
public class Main {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
// 注意 hasNext 和 hasNextLine 的区别
while (in.hasNext()) { // 注意 while 处理多个 case
int N = Integer.parseInt(in.nextLine());
while(N>0){
String str = in.nextLine();
Map<Character,Integer> map = new HashMap<>();
for(char b:str.toCharArray()){
if(map.get(b)==null) map.put(b,1);
else map.put(b,map.get(b)+1);
}
int[] res = new int[map.size()];
int i =0;
for(int b:map.values()){
res[i]=b;
i++;
}
for(i=0;i<res.length-1;i++){
for(int j=i+1;j<res.length;j++){
if(res[i]<res[j]){
int gg=res[i];
res[i]=res[j];
res[j]=gg;
}
}
}
int sum = 0;
int num = 26;
for(int b:res){
sum = sum + b*num;
num--;
}
System.out.println(sum);
N--;
}
}
}
}

