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 |
RE G++.神牛帮我看看#include<stdio.h> #include<string.h> const int WIDTH=20; int row,col,entry; int flag[WIDTH][WIDTH]; char grid[WIDTH][WIDTH]; int main() { int i,j; while(scanf("%d%d%d",&row,&col,&entry)) { if(!row&&!col&&!entry) break; memset(flag,0,sizeof(flag)); for(i=0;i<row;i++) scanf(" %s",grid[i]); bool Dis=true; i=0;j=entry-1; flag[i][j]=1; int ni,nj; while(1) { if(i<0||j<0||i>=row||j>=col)break; ni=i;nj=j; if(grid[ni][nj]=='N') { i--; if(flag[i][j]){Dis=false;break;} if(i<row-1) flag[i][j]=flag[i+1][j]+1; } else if(grid[ni][nj]=='S') { i++; if(flag[i][j]){Dis=false;break;} if(i>0) flag[i][j]=flag[i-1][j]+1; } else if(grid[ni][nj]=='W') { j--; if(flag[i][j]){Dis=false;break;} if(j<col-1) flag[i][j]=flag[i][j+1]+1; } else if(grid[ni][nj]=='E') { j++; if(flag[i][j]){Dis=false;break;} if(j>0) flag[i][j]=flag[i][j-1]+1; } } if(Dis) printf("%d step(s) to exit\n",flag[ni][nj]); else { printf("%d step(s) before a loop of %d step(s)\n",flag[i][j]-1,flag[ni][nj]-flag[i][j]+1); } } return 0; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator