#include <iostream>
using namespace std;
#define N 2010
char a[N], b[N], c[N];
inline void Print(int t, char b)
{
if(t>=4 || t<=1)
putchar('0');
else if(t==3)
putchar('1');
else
putchar(b);
}
int main()
{
int y, x, i, j, t;
char *pa, *pb, *pc, *pt;
a[0]=b[0]=c[0]='0';
while(scanf("%d%d", &y, &x)!=EOF)
{
getchar();
gets(a+1);
gets(b+1);
a[x+1]=b[x+1]='0';
pa=a;
pb=b;
pc=c;
// row 1
for(j=1; j<=x; ++j)
{
/** row 0 has all zeros
a is row 1 --- the row we are working on
b is row 2
*/
t = -240 + a[j-1] + a[j+1] + b[j-1] + b[j] + b[j+1];
Print(t, a[j]);
}
putchar('\n');
// row 2 to y-1
for(i=2; i<y; ++i)
{
/**
bug here: always read in new info into buffer c
and that is not what i want.
gets(c+1);
c[x+1]='0';
*/
gets(pc+1);
pc[x+1]='0';
/** pa points to row i-1
pb points to row i --- the row we are working on
c is row i+1
*/
for(j=1; j<=x; ++j)
{
t = -384 + pa[j-1] + pa[j] + pa[j+1] + pb[j-1] + pb[j+1] + pc[j-1] + pc[j] + pc[j+1];
Print(t, pb[j]);
}
putchar('\n');
/**
bug here: after serveral runs, pa, pb, pc all points to c
pa=pb;
pb=c;
*/
pt=pa;
pa=pb;
pb=pc;
pc=pt;
}
// row y
for(j=1; j<=x; ++j)
{
/** pa points to y-1st row
pb points to yth row --- the row we are working on
row y+1 has all zeros
*/
t = -240 + pa[j-1] + pa[j] + pa[j+1] + pb[j-1] + pb[j+1];
Print(t, pb[j]);
}
putchar('\n');
}
return 0;
}
- 1
- 2
前往页