漂亮度:每个字母的漂亮度都是在1-26之间;
最大漂亮度:求最值,当然是字母出现最多的取最大的漂亮度(26),依次递减求和
使用map进行去重求和,然后进行统计漂亮度。
import java.util.*;
public class Main{
public static void main(String [] args){
getButiful();
}
public static void getButiful(){
Scanner scan = new Scanner(System.in);
Integer num = Integer.valueOf(scan.nextLine());
for(int j = 0; j < num; j++){
String name = scan.nextLine();
int ret = 0;
int len = name.length();
Map<String,Integer> map = new HashMap<>();
for(int i = 0; i < len; i++){
char ch = name.charAt(i);
if(null != map.get(ch + "")){
map.put(ch + "",map.get(ch + "") + 1);
}else{
map.put(ch + "", 1);
}
}
List<Integer> list = new ArrayList<>();
for(String key : map.keySet()){
Integer val = map.get(key);
list.add(val);
}
Collections.sort(list);
int com = 26;
for(int i = list.size()-1; i >= 0; i--){
ret = ret + list.get(i)*com;
com--;
}
System.out.println(ret);
}
}
}

京公网安备 11010502036488号