uva 784

#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;

char maze[31][81];
char s[81];
int xx,yy;
int dx[4]={-1,0,1,0};
int dy[4]={0,1,0,-1};

void dfs(int x,int y);

int main()
{
 int T;
 char ch;
 char a[82];
 int k=0;

 scanf("%d",&T);
 getchar();
 while(T--)
 {
  int i=0,j;
  xx=-1;
  yy=-1;
  
  memset(maze,0,sizeof(maze));
  
  gets(a);
  while(a[0]!='_')
  {
            strcpy(maze[i],a);
   if(xx==-1&&yy==-1)
   {
    int len=strlen(a);
    for(int j=0;j<len;j++)
    {
     if(maze[i][j]=='*')
     {
      xx=i;
      yy=j;
     }
    }
   }
   gets(a);
   i++;
  }
  k=i;
  maze[xx][yy]='#';
  dfs(xx,yy);

  for(i=0;i<k;i++)
   puts(maze[i]);
  
  puts(a);
 }
 
 return 0;
}

void dfs(int x,int y)
{
 int i;
 for(i=0;i<4;i++)
 {
  int lx=x+dx[i];
  int ly=y+dy[i];
  
  if(maze[lx][ly]==' ')
  {
   maze[lx][ly]='#';
   dfs(lx,ly);
  }
 }
}

原文地址:https://www.cnblogs.com/Shirlies/p/2365481.html