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 |
贴代码#include<iostream> using namespace std; #include<string> #include<cstring> int main() { int m,n,t,bit[11][11],i,j,ans; string data[11]; while(cin>>m>>n>>t&&m&&n&&t) { memset(bit,0,sizeof(bit)); ans=0; for(int k=1;k<=m;k++) cin>>data[k]; i=1;j=t-1; while(1) { ++ans; if(bit[i][j]) { cout<<bit[i][j]-1<<" step(s) before a loop of "<<ans-bit[i][j]<<" step(s)"<<endl; break; } else bit[i][j]=ans;//记录步骤数 switch(data[i][j]) { case 'N':i--;break; case 'S':i++;break; case 'W':j--;break; case 'E':j++;break; } if(i<1||j<0||i>m||j>=n) { cout<<ans<<" step(s) to exit"<<endl; break; } } } return 0; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator