AcWing 4664. 字符统计
原题链接
简单
作者:
不知名的fE
,
2024-12-09 17:50:03
,
所有人可见
,
阅读 2
import java.util.*;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
String str = sc.nextLine();
HashMap<Character, Integer> map = new HashMap<>();
for (int i = 0; i < str.length(); i++) {
char j = str.charAt(i);
map.put(j, map.getOrDefault(j, 0) + 1);
}
LinkedList<Map.Entry<Character, Integer>> list = new LinkedList<>(map.entrySet());
list.sort((o1, o2) -> {
if (o1.getValue() != o2.getValue()) return o2.getValue() - o1.getValue();
return o1.getKey() - o2.getKey();
});
int max = list.get(0).getValue();
int i = 0;
while (i < list.size() && list.get(i).getValue() == max) {
System.out.print(list.get(i).getKey());
i++;
}
}
}