-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path복호화.java
More file actions
37 lines (32 loc) · 1.29 KB
/
복호화.java
File metadata and controls
37 lines (32 loc) · 1.29 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
// 복호화
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));
int n = Integer.parseInt(br.readLine());
for (int i = 0; i < n; i++) {
String arr = br.readLine();
Map<Character, Integer> charCount = new HashMap<>();
for (int j = 0; j < arr.length(); j++) {
char c = arr.charAt(j);
if (c != ' ') { // Ignore spaces
charCount.put(c, charCount.getOrDefault(c, 0) + 1);
}
}
List<Map.Entry<Character, Integer>> entryList = new ArrayList<>(charCount.entrySet());
entryList.sort((a, b) -> {
if (b.getValue().equals(a.getValue())) {
return Character.compare(a.getKey(), b.getKey());
}
return b.getValue() - a.getValue();
});
if (entryList.size() != 1 && entryList.get(0).getValue().equals(entryList.get(1).getValue())) {
System.out.println("?");
} else {
System.out.println(entryList.get(0).getKey());
}
}
}
}