题意:简单的dfs就可以了,水题
#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;
char a[100][100];
char b[100];
int dx[4]={-1,1,0,0};
int dy[4]={0,0,-1,1};
void dfs(int x,int y)
{
for(int i = 0 ; i < 4 ; i++)
{
int nx = x + dx[i];
int ny = y + dy[i];
if(a[nx][ny] == 1)
{
a[nx][ny] = 2;
dfs(nx,ny);
}
}
}
int main()
{
int n;
scanf("%d",&n);
getchar();
while(n--)
{
int x,y;
int t = 0;
memset(a,-1,sizeof(a));
while(1)
{
gets(b);
if(b[0] == '_')
break;
int len = strlen(b);
for(int i = 0 ; i < len ; i++)
{
if(b[i] == 'X')
a[t][i] = 0;
else if(b[i] == ' ')
a[t][i] = 1;
else if(b[i] == '*')
{
a[t][i] = 2;
x = t;
y = i;
}
}
t++;
}
dfs(x,y);
for(int i = 0 ; i < t ; i++)
{
for(int j = 0 ; a[i][j] != -1 ; j++)
{
if(a[i][j] == 0)
printf("X");
else if(a[i][j] == 1)
printf(" ");
else printf("#");
}
printf("\n");
}
printf("%s\n",b);
}
return 0;
}