-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbinary_string.cpp
More file actions
48 lines (45 loc) · 813 Bytes
/
binary_string.cpp
File metadata and controls
48 lines (45 loc) · 813 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
36
37
38
39
40
41
42
43
44
45
46
47
48
#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
using namespace std;
int main() {
/* Enter your code here. Read input from STDIN. Print output to STDOUT */
int N,k,t;
string ss;
cin>>N>>k>>t;
cin>>ss;
int array[N];
for(int i=0;i<N;i++){
array[i]=ss[i]-'0';
}
int j = 0;
while(t>0 and j<N-k ){
if(array[j]<array[j+k]){
array[j+k]=0;
array[j]=1;
t--;
if(t<=0) break;
int i=j-k;
while(i>=0){
if(array[i]<array[i+k]){
array[i]=1;
array[i+k]=0;
t--;
if(t<=0) break;
}
else{
break;
}
i-=k;
}
}
j++;
}
for(int i=0;i<N;i++){
cout<<array[i];
}
cout<<endl;
return 0;
}