实际上就是统计字符的频度,然后按照频度赋予分数,最后算总分。用一个map统计频度,然后按照频度高到低排序,依次递减算分即可。

public class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        while(in.hasNext()){
            int n = Integer.parseInt(in.nextLine().trim());
            //为什么不用int n = in.nextInt();?有兴趣的读者可以自行尝试,看看会出什么问题
            for(int i =0;i<n;++i){
                String str = in.nextLine();
                char[]chs = str.toCharArray();
                Map<Character,Integer> map = new HashMap<>();
                for(char c:chs){
                    if(map.get(c)==null)map.put(c,1);
                    else map.put(c,map.get(c)+1);
                }
                List<Map.Entry<Character,Integer>> list = new ArrayList<>(map.entrySet());
                Collections.sort(list,new Comparator<Map.Entry<Character,Integer>>(){
                    public int compare(Map.Entry<Character,Integer> o1,Map.Entry<Character,Integer> o2){
                        return o2.getValue()-o1.getValue();
                    }
                });
                int res = 0;
                int value = 26;
                for(Map.Entry<Character,Integer> entry:list){
                    res +=value--*entry.getValue();
                }
                System.out.println(res);
            }
        }
        
    }
}