-
Notifications
You must be signed in to change notification settings - Fork 0
/
AoC6a.java
37 lines (31 loc) · 962 Bytes
/
AoC6a.java
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.*;
class AoC6a {
public static void main(String[] argsf) {
Scanner scanner = new Scanner(System.in);
List<Map<Character, Integer>> allFreqs = new ArrayList<>();
while (scanner.hasNextLine()) {
String line = scanner.nextLine().trim();
char[] cs = line.toCharArray();
for (int i = 0; i < cs.length; i++) {
while (i >= allFreqs.size()) {
allFreqs.add(new HashMap<>());
}
Map<Character, Integer> freqs = allFreqs.get(i);
int c = freqs.getOrDefault(cs[i], 0);
freqs.put(cs[i], c+1);
}
}
for (Map<Character, Integer> map : allFreqs) {
int maxCount = 0;
char maxChar = ' ';
for (Map.Entry<Character, Integer> e : map.entrySet()) {
if (e.getValue() > maxCount) {
maxChar = e.getKey();
maxCount = e.getValue();
}
}
System.out.print(maxChar);
}
System.out.println();
}
}