此題是我做的搜索中最簡單的一道........很快就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;
}