题解 | #名字的漂亮度#
名字的漂亮度
https://www.nowcoder.com/practice/02cb8d3597cf416d9f6ae1b9ddc4fde3
// mark一下啦
// 记录每个字母出现的次数 直接使用字母对应的ASCII值为int数组的索引 对应的值就是字母出现的次数 不需要使用map了
import java.util.*;
public class Main {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
while (in.hasNextInt()) {
int n = in.nextInt();
// while中是 hasNextInt() 第一次nextInt()后 需要读字符串时 需要换行
in.nextLine();
for (int i = 0; i < n; i++) {
String s = in.nextLine();
int length = s.length();
int[] all = new int[75];
for (int j = 0; j < length; j++) {
all[s.charAt(j) - '0']++;
}
Arrays.sort(all);
int tmp = 26;
int ans = 0;
for (int k = 74; k >= 0; k--) {
if (all[k] <= 0) {
continue;
}
ans += (all[k] * tmp);
tmp--;
}
System.out.println(ans);
}
}
}
}
海康威视公司福利 1121人发布
