-
Notifications
You must be signed in to change notification settings - Fork 34
Expand file tree
/
Copy pathErase.java
More file actions
25 lines (22 loc) · 804 Bytes
/
Copy pathErase.java
File metadata and controls
25 lines (22 loc) · 804 Bytes
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
import java.util.Scanner;
public class Erase {
public static void main(final String[] args) {
try (final Scanner in = new Scanner(System.in)) {
final int count = in.nextInt() % 2;
final String initial = in.next();
final String done = in.next();
final String expected = getExpected(count, initial);
System.out.println((expected.equals(done)) ? "Deletion succeeded" : "Deletion failed");
}
}
private static String getExpected(final int count, final String initial) {
if (count == 0) {
return initial;
}
return initial
.replace('0', 'a')
.replace('1', 'b')
.replace('a', '1')
.replace('b', '0');
}
}