C202301 @ 2023-08-21 22:18:55
#include<iostream>
using namespace std;
int main()
{
int n,b,c,d,e;
cin>>n;
char a[40][40];
bool color=0;
for(b=1;b<=n;b++)
{
for(c=1;c<=n;c++)
cin>>a[b][c];
}
for(d=1;d<=n;d++)
{
for(e=1;e<=n;e++)
{
if(a[d][e]=='1')
{
cout<<'1'<<" ";
continue;
}
for(int f=d;f>=1;f--)
if(a[f][e]=='1')
{
color=1;
break;
}
if(color==0)
{
cout<<'0'<<" ";
continue;
}
color=0;
for(int f=d;f<=n;f++)
if(a[f][e]=='1')
{
color=1;
break;
}
if(color==0)
{
cout<<'0'<<" ";
continue;
}
color=0;
for(int f=e;f>=1;f--)
if(a[d][f]=='1')
{
color=1;
break;
}
if(color==0)
{
cout<<'0'<<" ";
continue;
}
color=0;
for(int f=e;f<=n;f++)
if(a[d][f]=='1')
{
color=1;
break;
}
if(color==0)
{
cout<<'0'<<" ";
continue;
}
cout<<'2'<<" ";
}
cout<<endl;
}
return 0;
}
by Guoyh @ 2023-08-21 22:36:03
@C202301 上下左右都有1并不一定就在闭合圈里面,你想想这个图
11110000
10010000
10110111
10100101
10111101
10000001
11111111
by C202301 @ 2023-08-21 22:50:50
知道了,谢谢!