-
Notifications
You must be signed in to change notification settings - Fork 1
/
HolesInTheText.java
57 lines (48 loc) · 1.08 KB
/
HolesInTheText.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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
import java.util.*;
import java.io.*;
class HolesInTheText {
public static void main(String[] args) {
try {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int numLines = Integer.parseInt(br.readLine());
for (int i = 0; i < numLines; i++) {
String line = br.readLine();
int holes = numHoles(line);
System.out.println(holes);
}
} catch (IOException e) {}
}
public static int numHoles (String str) {
int holes = 0;
for (char ch : str.toCharArray()) {
/*for (int i = 0; i < str.length(); i++) {
char ch = str.charAt(i);*/
final HashSet<Character> hs = getSet();
if (ch == 'B') {
holes += 2;
} else if (hs.contains(ch)) {
/* //Alternatively
} else if (ch == 'A' ||
ch == 'D' ||
ch == 'O' ||
ch == 'P' ||
ch == 'Q' ||
ch == 'R')
{
*/
holes ++;
}
}
return holes;
}
private static HashSet<Character> getSet() {
HashSet<Character> hs = new HashSet<Character>();
hs.add('A');
hs.add('D');
hs.add('O');
hs.add('P');
hs.add('Q');
hs.add('R');
return hs;
}
}