Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
i 没在函数内部定义引发的血案!!!!#include <iostream> #include <cstdio> using namespace std; const int M = 1005; int i,j; int m,n; char map [101][101]; int dir[8][2] = { {-1,-1}, {-1,0}, {-1,1}, {0,1}, {1,1}, {1,0}, {1,-1}, {0,-1} }; void DFS(int x,int y) { int xx,yy; int i; map[x][y] = '*' ;//保证不再遍历这个方格。 for(i=0;i<8;i++) { xx = x + dir[i][0]; yy = y + dir[i][1]; if (xx<0||yy<0||xx>=m||yy>=n) continue ; if (map[xx][yy] == '@' ) DFS(xx,yy); } } int main () { int ans; while (scanf("%d%d",&m,&n)&&m!=0) { for (i=0;i<m;i++) scanf("%s",map[i]); ans = 0; for (i=0;i<m;i++) { for (j=0;j<n;j++) { if (map[i][j] == '@') { DFS(i,j) ; ans ++; } } } printf("%d\n",ans ); } return 0; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator