64分求救
查看原帖
64分求救
975726
C202301楼主2023/8/21 22:18
#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;
}
2023/8/21 22:18
加载中...