-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path영단어 암기는 괴로워.java
More file actions
42 lines (34 loc) · 1.35 KB
/
영단어 암기는 괴로워.java
File metadata and controls
42 lines (34 loc) · 1.35 KB
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
30
31
32
33
34
35
36
37
38
39
40
41
42
// 영단어 암기는 괴로워
import java.util.*;
import java.lang.*;
import java.io.*;
class Main {
public static void main(String[] args) throws IOException{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
StringTokenizer st = new StringTokenizer(br.readLine());
int n = Integer.parseInt(st.nextToken());
int m = Integer.parseInt(st.nextToken());
Map<String, Integer> map = new HashMap<>();
for (int i = 0; i < n; i++) {
String input = br.readLine();
if (input.length() >= m) {
map.put(input, map.getOrDefault(input, 0) + 1);
}
}
List<Map.Entry<String, Integer>> entryList = new ArrayList<>(map.entrySet());
entryList.sort((a, b) -> {
if (!a.getValue().equals(b.getValue())) {
return b.getValue() - a.getValue();
}
if (a.getKey().length() != b.getKey().length()) {
return b.getKey().length() - a.getKey().length();
}
return a.getKey().compareTo(b.getKey());
});
StringBuilder sb = new StringBuilder();
for (int i = 0; i < entryList.size(); i++) {
sb.append(entryList.get(i).getKey()).append("\n");
}
System.out.println(sb);
}
}