UVa 784 - Maze Exploration

此题是我做的搜索中最简单的一道........很快就AC了,主要要注意scanf和gets输入之间的差别,,,,scanf后要把后面的换行符用getchar取走,不然gets会出错.....

#include<cstdio>
#include<cstring>
const int LINE=32;
const int CLOUMN=82;
char str[LINE][CLOUMN];
int row,col;
int h;
void init()
{
	int i;
	row=0;col=0;
	memset(str, 0, sizeof(str));
	for( i=0; i<30; i++)
	{
		gets(str[i]);
		if(str[i][0] == '_')
			break;
		if(strchr(str[i],'*'))
		{
			col=strchr(str[i],'*')-str[i];
			row=i;
		}
	}
	h=i;
}
int dx[4]={0,-1,0,1};
int dy[4]={-1,0,1,0};
void dfs(int x, int y)
{
	str[x][y]='#';
	int nx,ny;
	for(int i=0; i<4; i++)
	{
		nx=x+dx[i];
		ny=y+dy[i];
		if(str[nx][ny] == ' ')
		{
			//str[nx][ny]='#';
			dfs(nx,ny);
		}
	}
}
int main()
{
	int n;
	scanf("%d", &n);
	getchar();
	while(n--)
	{
		init();
		dfs(row,col);
		for(int i=0; i<=h; i++)
			printf("%s\n",str[i]);
	}
	return 0;
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值