水题……
#include<iostream>
using namespace std;
int main()
{
int row, col, startx, starty;
char map[11][11];
int step[11][11];
bool visited[11][11];
int ans1, ans2, temp;
while( cin>>row>>col && row&&col )
{
cin>>starty;
for(int i=0; i<row; i++)
cin>>map[i];
startx = 0;
starty--;
step[startx][starty]=0;
memset(visited, 0, sizeof(visited));
visited[startx][starty]=1;
while( 1 )
{
temp = step[startx][starty];
switch(map[startx][starty])
{
case 'N':startx--;break;
case 'S':startx++;break;
case 'E':starty++;break;
case 'W':starty--;break;
}
if( startx<0||startx>=row || starty<0||starty>=col)
{
cout<<temp+1<<" step(s) to exit"<<endl;
break;
}
else
{
if( visited[startx][starty] )
{
ans1 = step[startx][starty];
ans2 = temp-step[startx][starty]+1;
cout<<ans1<<" step(s) before a loop of "<<ans2<<" step(s)"<<endl;
break;
}
else
{
visited[startx][starty]=1;
step[startx][starty] = temp+1;
}
}
}
}
}