- Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathHolesInTheText.java
More file actions
Latest commit
57 lines (48 loc) · 1.08 KB
/
Copy pathHolesInTheText.java
File metadata and controls
57 lines (48 loc) · 1.08 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
47
48
49
50
51
52
53
54
55
56
57
importjava.util.*;
importjava.io.*;
classHolesInTheText {
publicstaticvoidmain(String[] args) {
try {
BufferedReaderbr = newBufferedReader(newInputStreamReader(System.in));
intnumLines = Integer.parseInt(br.readLine());
for (inti = 0; i < numLines; i++) {
Stringline = br.readLine();
intholes = numHoles(line);
System.out.println(holes);
}
} catch (IOExceptione) {}
}
publicstaticintnumHoles (Stringstr) {
intholes = 0;
for (charch : str.toCharArray()) {
/*for (int i = 0; i < str.length(); i++) {
char ch = str.charAt(i);*/
finalHashSet<Character> hs = getSet();
if (ch == 'B') {
holes += 2;
} elseif (hs.contains(ch)) {
/* //Alternatively
} else if (ch == 'A' ||
ch == 'D' ||
ch == 'O' ||
ch == 'P' ||
ch == 'Q' ||
ch == 'R')
{
*/
holes ++;
}
}
returnholes;
}
privatestaticHashSet<Character> getSet() {
HashSet<Character> hs = newHashSet<Character>();
hs.add('A');
hs.add('D');
hs.add('O');
hs.add('P');
hs.add('Q');
hs.add('R');
returnhs;
}
}