-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPasswordPhilosophyTwoTwo.java
More file actions
41 lines (34 loc) · 1.18 KB
/
PasswordPhilosophyTwoTwo.java
File metadata and controls
41 lines (34 loc) · 1.18 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
import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
public class PasswordPhilosophyTwoTwo {
public static void main(String[] args) {
BufferedReader reader = null;
try {
reader = new BufferedReader(new FileReader("passwordphilosophy.txt"));
} catch (FileNotFoundException e) {
e.printStackTrace();
}
int count = 0;
try {
String s = reader.readLine();
while (s != null) {
String[] parts = s.split(" ");
String[] limits = parts[0].split("-");
int idxA = Integer.parseInt(limits[0]) - 1;
int idxB = Integer.parseInt(limits[1]) - 1;
char letter = parts[1].charAt(0);
String password = parts[2];
if ((password.charAt(idxA) == letter) ^ (password.charAt(idxB) == letter)) {
count++;
}
s = reader.readLine();
}
reader.close();
} catch (IOException e) {
e.printStackTrace();
}
System.out.println(count);
}
}