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 |
修改后的代码In Reply To:哪位大大,看看,咋错了? Posted by:xiaolijian at 2010-08-03 10:55:32 #include <stdio.h> #include <stdlib.h> #include <string.h> #define N 21 int h,w,count=1,x0,y0; char a[N][N]; const int d[4][2]={{-1,0},{1,0},{0,-1},{0,1}};//前面定义错误 int check(int x,int y) { int j; if(x<0||x>=h||y<0||y>=w||'#'==a[x][y]||a[x][y]=='0'||a[x][y]=='@') j=-1; else j=1; return j; } void dfs(int x,int y) { int i,j,x1,y1; for(i=0;i<4;i++) { x1=x+d[i][0]; y1=y+d[i][1]; j=check(x1,y1); if(j==1) { count++; a[x1][y1]='0'; dfs(x1,y1); } } return ; } int main() { int i,j; while(scanf("%d%d",&w,&h)&&h!=0&&w!=0) { memset(a,0,sizeof(a));// count=1; //前面赋值在外面 for(i=0;i<h;i++) scanf("%s",a[i]); for(i=0;i<h;i++) { for(j=0;j<w;j++) { if(a[i][j]=='@') { x0=i; y0=j; } } } dfs(x0,y0); printf("%d\n",count); } return 0; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator