Start: Jan, 08, 2019 19:01:00
2018年秋季学期程序设计基础(C语言)期末考试
End: Jan, 08, 2019 21:46:00
Time elapsed:
Time remaining:

Problem_ID: H
Result: Accepted
Time: 6ms
Memory: 1104kB
In contest: 1258

#include <stdio.h>
#include <math.h>
#include <stdlib.h>
#include <string.h>
#define max(a,b) (a>b?a:b)
#define min(a,b) (a>b?b:a)
char map[110][110];
int n,m;
int xmode[]={0,1,0,-1};
int ymode[]={1,0,-1,0};
int check(int x,int y)
{
	int sum=0;
	for(int i=-1;i<2;i++)
	{
		for(int j=-1;j<2;j++)
		{
			if(x+i>=n||x+i<0||y+j>=m||y+j<0||(i==0&&j==0))continue;
			if(map[x+i][y+j]=='L')sum++;			
		}
	}
	return sum;
}
void dfs(int x,int y)
{
	if(x>=n||x<0||y>=m||y<0||map[x][y]=='0')return ;	
	if(check(x,y)==0)
	{
		map[x][y]='0';
		for(int i=0;i<4;i++)
		{
			dfs(x+xmode[i],y+ymode[i]);
		}
	}
	return ;
}
int main()
{
	scanf("%d%d",&n,&m);
	getchar();
	for(int i=0;i<n;i++)
	gets(map[i]);
	int x,y;
	scanf("(%d,%d)",&x,&y);
	dfs(x,y);
	map[x][y]='0';
	for(int i=0;i<n;i++)
	{
			printf("%s\n",map[i]);
	}
	return 0;
}