-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCustomCustomsSixTwo.java
More file actions
46 lines (42 loc) · 1.45 KB
/
CustomCustomsSixTwo.java
File metadata and controls
46 lines (42 loc) · 1.45 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
43
44
45
46
import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
public class CustomCustomsSixTwo {
public static void main(String[] args) {
BufferedReader reader = null;
try {
reader = new BufferedReader(new FileReader("customcustoms.txt"));
} catch (FileNotFoundException e) {
e.printStackTrace();
}
int totalCount = 0;
try {
String input = reader.readLine();
Map<Character, Integer> questions = new HashMap<>();
int personCount = 0;
while (input != null) {
if (input.equals("")) {
for (Character c : questions.keySet()) {
if (questions.get(c) == personCount) {
totalCount++;
}
}
questions.clear();
personCount = 0;
} else {
for (int idx = 0; idx < input.length(); idx++) {
questions.put(input.charAt(idx), questions.getOrDefault(input.charAt(idx), 0) + 1);
}
personCount++;
}
input = reader.readLine();
}
} catch (IOException e) {
e.printStackTrace();
}
System.out.println(totalCount);
}
}