标签:
Sample Output
1 #include<cstdio> 2 #include<cstring> 3 using namespace std; 4 5 int d[8][2]={1,0,0,1,-1,0,0,-1,-1,-1,-1,1,1,1,1,-1}; 6 char g[105][105]; 7 int id,m,n; 8 9 void dfs(int x,int y) 10 { 11 if(x<0||y<0||x>=m||y>=n||g[x][y]==‘*‘) 12 return; 13 g[x][y]=‘*‘; 14 for(int i=0;i<8;i++) 15 { 16 int xx=x+d[i][0]; 17 int yy=y+d[i][1]; 18 dfs(xx,yy); 19 } 20 } 21 22 int main() 23 { 24 int i,j; 25 while(scanf("%d%d",&m,&n),m|n) 26 { 27 id=0; 28 for(i = 0;i < m;i++) 29 scanf("%s",g[i]); 30 for(i = 0;i < m;i++) 31 for(j = 0;j < n;j++) 32 { 33 if(g[i][j]!=‘*‘) 34 { 35 id++; 36 dfs(i,j); 37 } 38 } 39 printf("%d\n",id); 40 } 41 return 0; 42 }
标签:
原文地址:http://www.cnblogs.com/homura/p/4699659.html