题解 | #名字的漂亮度#
名字的漂亮度
https://www.nowcoder.com/practice/02cb8d3597cf416d9f6ae1b9ddc4fde3
import java.util.Arrays; import java.util.Comparator; import java.util.Scanner; // 注意类名必须为 Main, 不要有任何 package xxx 信息 public class Main { public static void main(String[] args) { Scanner in = new Scanner(System.in); int n = Integer.parseInt(in.nextLine()); while (n-- > 0) { String word = in.nextLine(); int[] counts = new int[26]; for (int i = 0; i < word.length(); i++) { counts[word.charAt(i) - 'a']++; } Arrays.sort(counts); int beauty = 1; int result = 0; for (int count : counts) { result += beauty * count; beauty++; } System.out.println(result); } } }