#include<iostream> using namespace std; struct { int x,y; int step; char c; }map[11][11]; int main() { int n,m,l,i,j,a,b; while(cin>>n>>m>>l&&(n||m||l)) { getchar();//细节还是犯错了 char c; memset(map,0,sizeof(map)); for(i=1;i<=n;i++) { for(j=1;j<=m;j++) { scanf("%c",&c); switch(c){//这个语句折腾了好久特别是方向的设定 case 'W': map[i][j].x= 0,map[i][j].y=-1,map[i][j].step=0,map[i][j].c='W';break; case 'E': map[i][j].x= 0,map[i][j].y= 1,map[i][j].step=0,map[i][j].c='E';break; case 'N': map[i][j].x=-1,map[i][j].y= 0,map[i][j].step=0,map[i][j].c='N';break; case 'S': map[i][j].x= 1,map[i][j].y= 0,map[i][j].step=0,map[i][j].c='S';break; default: break; } } getchar(); } /*cout<<endl; for(i=1;i<=n;i++) { for(j=1;j<=m;j++) cout<<map[i][j].c; cout<<endl; }*/ i=1,j=l; int s=0; while(1) { map[i][j].step=++s; int x=map[i][j].x; int y=map[i][j].y; i+=x; j+=y; if(map[i][j].step!=0) { a=map[i][j].step-1; b=s-map[i][j].step+1; break;} if(i<1||i>n||j<1||j>m) { a=s;b=0; break;} } if(b!=0) printf("%d step(s) before a loop of %d step(s)/n",a,b); else printf("%d step(s) to exit/n",a); } return 0; } http://162.105.81.212/JudgeOnline/problem?id=1573