hdu1312

来源:互联网 发布:app软件页面模板源码 编辑:程序博客网 时间:2024/06/05 23:57

http://acm.hdu.edu.cn/showproblem.php?pid=1312

#include<stdio.h>#include<string.h>char map[25][25];int n,m,cont;void dfs(int x,int y){    if(map[x][y]=='#') return;    if(x<0||y<0||x>=m||y>=n) return;//先判断是否出边界,然后计数    if(map[x][y]=='@'||map[x][y]=='.') map[x][y]='#',cont++;               dfs(x,y+1);    dfs(x-1,y);             dfs(x+1,y);                dfs(x,y-1);}int main(){  int i,j;  while(scanf("%d%d",&n,&m),n||m)  {      cont=0;      getchar();      for(i=0;i<m;i++)      {          for(j=0;j<n;j++)            scanf("%c",&map[i][j]);          getchar();      }    for(i=0;i<m;i++)        for(j=0;j<n;j++)        if(map[i][j]=='@')    {        dfs(i,j);    }      printf("%d\n",cont);  }return 0;}


1 0