-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMain.java
More file actions
30 lines (24 loc) · 972 Bytes
/
Main.java
File metadata and controls
30 lines (24 loc) · 972 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
import java.util.*;
import java.util.stream.Collectors;
public class Main {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
String s = scanner.nextLine();
TreeMap<Character, Integer> map = new TreeMap<Character, Integer>();
for (Character c : s.toCharArray()) {
if ((c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z')) {
Integer cout = map.get(c);
map.put(c, null == cout ? 1 : cout + 1);
}
}
Collection<Integer> values = map.values();
List<Integer> list = values.stream().sorted().collect(Collectors.toList());
for (int i = list.size(); i >= 0; i--) {
for (Map.Entry<Character, Integer> entry : map.entrySet()) {
if (i == entry.getValue()) {
System.out.println((entry.getKey() + ":" + entry.getValue() + ";"));
}
}
}
}
}