-
-
Notifications
You must be signed in to change notification settings - Fork 110
/
Copy pathCipher.java
41 lines (39 loc) · 1.04 KB
/
Cipher.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
import java.io.*;
import java.util.*;
public class Solution {
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);
//xor=x(xor,cur);
}
else if(i<n){
xor=x(xor,str[i-k]);
cur=x(xor,num);
//xor=x(xor,cur);
}
xor=num;
str[i]= cur;
//System.out.println(str[i]);
}
for(int i=0;i<n;i++){
System.out.print(str[i]);
}
}
public static int x(int a,int b){
if(a==b)
return 0;
else
return 1;
}
}