题解 | #名字的漂亮度#
名字的漂亮度
https://www.nowcoder.com/practice/02cb8d3597cf416d9f6ae1b9ddc4fde3
import java.util.Scanner; import java.util.*; // 注意类名必须为 Main, 不要有任何 package xxx 信息 public class Main { public static void main(String[] args) { Scanner in = new Scanner(System.in); int n = in.nextInt(); in.nextLine(); for (int i = 0; i < n; i++) { String str = in.nextLine(); str = str.toUpperCase(); char[] charArray = str.toCharArray(); int[] intArray = new int[26]; for (char c : charArray) { intArray[c - 'A']++; } Arrays.sort(intArray); int num = 0; for (int j = intArray.length - 1; j >= 0; j--) { num += (26 - (intArray.length - 1 - j)) * intArray[j]; } System.out.println(num); } } }