zoukankan      html  css  js  c++  java
  • 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);
      }
     }
    }

  • 相关阅读:
    STL中的string
    STL中的map
    STL中的set和multiset
    C++基础知识
    希尔排序
    桶排序
    归并排序
    堆排序
    数组左边奇数右边偶数算法O(n)
    背包问题 洛谷P1164 小A点菜
  • 原文地址:https://www.cnblogs.com/Shirlies/p/2365481.html
Copyright © 2011-2022 走看看