Psst.. new poll here.
Psst.. new forums here.
Microsoft is blocking us again (TY IP Reputation!) so just use oauth login instead. :)
Paste
Pasted as C++ by ariful ( 6 years ago )
#include<bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
#define ll long long
#define pb push_back
#define mp make_pair
#define loop(i,a,n) for(int i=a;i<=n;++i)
#define clr(x) memset(x,0,sizeof x)
#define min3(a,b,c) min(a,min(b,c))
#define max3(a,b,c) max(a,max(b,c))
#define min4(a,b,c,d) min(a,min(b,min(c,d)))
#define max4(a,b,c,d) max(a,max(b,max(c,d)))
#define fast ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define pii pair<int,int>
#define pll pair<ll,ll>
#define pli pair<ll,int>
#define pil pair<int,ll>
#define FF first
#define SS second
#define PI acos(-1.0)
#define bug cout<<"ok"<<endl;
using namespace std;
using namespace __gnu_pbds;
typedef tree<int , null_type,less<int>,
rb_tree_tag, tree_order_statistics_node_update> anik;
const int MOD = 1e9 + 7;
const ll MX= 1e9;
const ll INF = 1e9;
main()
{
int t;
cin>>t;
while(t--)
{
string s,ans;
cin>>s;
int n,l;
cin>>n;
l=s.length();
bool f=0;
for(int i=0;i<l;++i)
{
if(s[i]=='1' && i<n && i+n<l)
{
ans[i+n]='1';
}
else if(s[i]=='0' && i<n && i+n<l)
{
ans[i+n]='0';
}
else if(i>=n && i-n<n)
{
if(s[i]=='1')
{
ans[i-n]='1';
if(i+n<l)ans[i+n]='1';
}
else
{
ans[i-n]='0';
if(i+n<l)ans[i+n]='0';
}
}
else
{
if(s[i]=='1')
{
if(i+n<l)ans[i+n]='1';
if(ans[i-n]=='1')continue;
else f=1;break;
}
else
{
if(i+n<l)ans[i+n]='0';
if(ans[i-n]=='0')continue;
else f=1;break;
}
}
}
if(f==1)cout<<-1<<endl;
else
{
for(int i=0;i<l;++i)cout<<ans[i];
cout<<endl;
}
}
}
Revise this Paste