rambless
名字的漂亮度
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 = in.nextInt();
in.nextLine();
for(int i=0; i<n; i++) {
judge(in.nextLine());
}
}
}
private static void judge(String temp) {
temp = temp.toLowerCase();
char[] arr = temp.toCharArray();
int[] array = new int[26];
Arrays.fill(array, 0);
for(int i=0; i<arr.length; i++) {
array[arr[i]-97]++;
}
Arrays.sort(array);
int sum = 0;
int val = 26;
for(int i=array.length-1; i>=0; i--) {
if(array[i]==0) {
break;
}
sum += array[i]*val;
val--;
}
System.out.println(sum);
}
}

查看7道真题和解析