分析:大模拟,没什么好说的.我在考场上犯了一个超级低级的错误:while (scanf("%s",s + 1)),导致了死循环,血的教训啊,以后要记住了.
/*
1.没有发生改变,check一下
2.将一位1变成0
3.添一位
4.减一位
*/
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm> using namespace std; int n,len,ss[],b[];
char s[];
bool flag = false; bool check()
{
int res = ;
for (int i = ;i <= n; i++)
if (ss[i] == )
res += i;
if (res % (n + ) == )
return true;
return false;
} bool check2()
{
int res = ;
for (int i = ; i <= n; i++)
if (b[i] == )
res += i;
if (res % (n + ) == )
return true;
return false;
} void print()
{
for (int i = ; i <= n; i++)
printf("%d",ss[i]);
printf("\n");
} void add(int x,int y)
{
memcpy(b,ss,sizeof(ss));
for (int i = n; i > x; i--)
b[i] = b[i-];
b[x] = y;
if (check2())
{
memcpy(ss,b,sizeof(ss));
flag = ;
}
} void eras(int x)
{
memcpy(b,ss,sizeof(ss));
for (int i = x; i <= n; i++)
b[i] = b[i + ];
if (check2())
{
memcpy(ss,b,sizeof(ss));
flag = ;
}
} int main()
{
scanf("%d",&n);
while(scanf("%s",s + ) != EOF)
{
memset(b,,sizeof(b));
len = strlen(s + );
flag = false;
if (abs(n - len) > )
{
printf("-1\n");
continue;
}
for (int i = ; i <= len; i++)
ss[i] = s[i] - '';
if (n == len)
{
if (check()) //
{
print();
continue;
}
for (int i = ; i <= n; i++) //
{
if (ss[i] == )
{
ss[i] = ;
if (check())
{
flag = ;
break;
}
ss[i] = ;
}
}
}
if (flag)
{
print();
continue;
}
if (len == n - )
{
for (int i = ; i <= n + ; i++) //
for (int j = ; j <= ; j++)
{
add(i,j); //i位以及以后都要往后挪1
if (flag)
break;
}
}
if (flag)
{
print();
continue;
}
if (len == n + )
{
for (int i = ; i <= n; i++)
{
eras(i);
if (flag)
break;
}
}
if (flag)
{
print();
continue;
}
printf("-1\n");
} return ;
}