| ||||||||||
| 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:不过。。。为什么啊(附代码)In Reply To:这个测试用例很管用! Posted by:BrainDeveloper at 2008-12-10 20:02:48 #include<iostream>
#include<fstream>
using namespace std;
#define MAX 12
char map[MAX][MAX];
int R,C;
int i,j;
int step[MAX][MAX];
void st(int &k)
{
switch(map[i][j])
{
case 'N':i--;break;
case 'S':i++;break;
case 'W':j--;break;
case 'E':j++;break;
}
if(i<0||j<0||i>R||j>C||step[i][j]!=-1)
return ;
step[i][j]=k++;
st(k);
}
int main()
{
int K,k;
//ifstream fin;
//fin.open("D:\\in.txt");
while(cin>>R>>C>>K&&R!=0&&C!=0&&K!=0)
{
k=1;
memset(step,-1,MAX*MAX);
for(int in=0;in<R;in++)
for(int jn=0;jn<C;jn++)
cin>>map[in][jn];
i=0;j=K-1;
step[i][j]=0;
st(k);
if(i<0||j<0||i>R||j>C)
{
cout<<k<<" step";
if(k!=1)
cout<<"(s)";
cout<<" to exit"<<endl;
}
else
{
k-=step[i][j];
cout<<step[i][j]<<" step";
if(step[i][j]!=1)
cout<<"(s)";
cout<<" before a loop of "<<k<<" step(s)"<<endl;
}
}
return 0;
}
Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator