forked from rajatgoyal715/Hackerrank
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCipher.java
More file actions
35 lines (33 loc) · 954 Bytes
/
Cipher.java
File metadata and controls
35 lines (33 loc) · 954 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
26
27
28
29
30
31
32
33
34
35
import java.util.*;
import java.io.*;
class Cipher{
public static void main(String[] args) throws IOException{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
String item[] = br.readLine().split(" ");
int n = Integer.parseInt(item[0]);
int k = Integer.parseInt(item[1]);
int c = br.read()-48;
int str[] = new int[n];
str[0] = c;
int cur = c;
int xor = cur;
for (int i = 1; i < n; i++) {
int num = br.read() - 48;
if(i < k) {
cur = x(xor, num);
}
else if(i < n) {
xor = x(xor, str[i-k]);
cur = x(xor, num);
}
xor = num;
str[i] = cur;
}
for (int i = 0; i < n; i++) {
System.out.print(str[i]);
}
}
public static int x(int a, int b) {
return a == b ? 0 : 1;
}
}