题解 | #名字的漂亮度#
名字的漂亮度
https://www.nowcoder.com/practice/02cb8d3597cf416d9f6ae1b9ddc4fde3
import java.awt.List; import java.io.BufferedReader; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.text.DateFormat; import java.text.DecimalFormat; import java.time.LocalDate; import java.time.LocalDateTime; import java.time.temporal.ChronoUnit; import java.util.*; import java.util.stream.IntStream; import java.util.stream.Stream; import static java.util.Arrays.*; import static java.util.stream.Stream.*; public class Main { public static void main(String[] args) throws IOException { testTh(); } private static void testTh() throws IOException { BufferedReader bf = new BufferedReader(new InputStreamReader(System.in)); String str; StringBuilder sb = new StringBuilder(); DecimalFormat df = new DecimalFormat("#0.0"); int parseInt = Integer.parseInt(bf.readLine()); int[] count = new int[parseInt]; int j = 0; while ((str = bf.readLine()) != null) { char[] chars = str.toCharArray(); TreeMap<String, Integer> hashMap = new TreeMap<>(); for (char aChar : chars) { String s = aChar + ""; if (hashMap.containsKey(s)) { Integer integer = hashMap.get(s); integer++; hashMap.put(s, integer); } else { hashMap.put(s, 1); } } Set<Map.Entry<String, Integer>> entries = hashMap.entrySet(); ArrayList<Map.Entry<String, Integer>> al = new ArrayList<>(entries); Collections.sort(al, new Comparator<Map.Entry<String, Integer>>() { @Override public int compare(Map.Entry<String, Integer> o1, Map.Entry<String, Integer> o2) { int i = o2.getValue() - o1.getValue(); return i; } }); int i = 26; for (Map.Entry<String, Integer> entry : al) { count[j] = count[j] + entry.getValue() * (i--); } j++; } Arrays.stream(count).forEach(System.out::println); } }