描述 |
给出一个名字,该名字有26个字符串组成,定义这个字符串的“漂亮度”是其所有字母“漂亮度”的总和。 |
---|---|
知识点 | 字符串 |
运行时间限制 | 0M |
内存限制 | 0 |
输入 |
整数N,后续N个名字 N个字符串,每个表示一个名字
|
输出 |
每个名称可能的最大漂亮程度 |
样例输入 | 2 zhangsan lisi |
样例输出 | 192 101 |
import java.util.Arrays;
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
int nextInt = scanner.nextInt();
scanner.nextLine();
int[] score = new int[nextInt];
for (int i = 0; i < nextInt; i++) {
char[] arr = scanner.nextLine().toCharArray();
int[] count = new int[26];
for (int j = 0; j < arr.length; j++) {
int index = arr[j]-'a';
count[index]++;
}
Arrays.sort(count);
for (int j = count.length-1; j >= 0 && count[j] != 0; j--) {
score[i] += (j+1)*count[j];
}
}
for (int i = 0; i < score.length; i++) {
System.out.println(score[i]);
}
}
}