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 |
纪念AC!#include<stdio.h> #include<memory.h> char smap[12][12]; int map[12][12]; int main() { int r,c,start; int i,total; int x,y; int flag; while(scanf("%d%d%d",&r,&c,&start)!=EOF){ if(r==0&&c==0&&start==0) return 0; memset(map,0,sizeof(map)); for(i=1;i<=r;i++) scanf("%s",&smap[i]); x=1;y=start-1; flag=1; total=0; while(flag){ switch(smap[x][y]){ case 'E':y++; break; case 'W':y--; break; case 'N':x--; break; case 'S':x++; break; } if(x>=1&&x<=r&&y>=0&&y<=c-1){ if(!map[x][y]){ total++; map[x][y]=total; } else{ printf("%d step(s) before a loop of %d step(s)\n",map[x][y],total-map[x][y]+1); flag=0; } } else { printf("%d step(s) to exit\n",total+1); flag=0; } } } return 0; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator