#include<iostream>
#include<cstring>
#include<cstdio>
using namespace std;
char grid[35][85];
bool visit[35][85];
void fillgrid(int x,int y)
{
grid[x-1][y-1]='#';
grid[x-1][y]='#';
grid[x-1][y+1]='#';
grid[x][y-1]='#';
grid[x][y]='#';
grid[x][y+1]='#';
grid[x+1][y-1]='#';
grid[x+1][y]='#';
grid[x+1][y+1]='#';
}
void dfs(int x,int y)
{
fillgrid(x,y);
char wall=grid[1][0];
if (grid[x-2][y]!=wall&&!visit[x-2][y])
{
grid[x-2][y]='#';
visit[x-2][y]=1;
dfs(x-4,y);
}
if (grid[x][y-2]!=wall&&!visit[x][y-2])
{
grid[x][y-2]='#';
visit[x][y-2]=1;
dfs(x,y-4);
}
if (grid[x][y+2]!=wall&&!visit[x][y+2])
{
grid[x][y+2]='#';
visit[x][y+2]=1;
dfs(x,y+4);
}
if (grid[x+2][y]!=wall&&!visit[x+2][y])
{
grid[x+2][y]='#';
visit[x+2][y]=1;
dfs(x+4,y);
}
}
void print(int r)
{
for (int i=0;i<=r;i++)
{
for (int j=0;j<80;j++)
{
cout<<grid[i][j];
}
}
}
int main()
{
int n;
cin>>n;
char input=getchar();
while(n--)
{
int row=0;
memset(grid,' ',sizeof(grid));
while(cin.getline(grid[row],85)&&grid[row][0]!='_')
{
row++;
}
memset(visit,0,sizeof(visit));
int stx=0,sty;
for (int i=0;;i++)
{
for (int j=2;j<81;j=j+4)
{
if (grid[i][j]=='*')
{
stx=i;
sty=j;
break;
}
}
if (stx!=0) break;
}
dfs(stx,sty);
print(row);
}
return 0;
}
uva784
最新推荐文章于 2021-02-04 23:48:16 发布