没有技术含量的水题……一次性0msAC;
/**
* @file source.cpp
* @author hybest
* @date 2013-07-1573
* @description
* ACM/ICPC train: Robot Motion
*/
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<string>
#include<stack>
#include<map>
#include<queue>
#include<algorithm>
using namespace std;
char grid[16][16];
int vis[16][16];
int main()
{
int n, m, x, y, i, j, step, flag;
while( scanf( "%d %d %d", &n, &m, &y ) && n && m && y )
{
x = 0;
y = y - 1;
step = 0;
flag = 0;
memset( vis, 0, sizeof(vis) );
for( i = 0; i < n; i++ )
{
scanf( "%s", grid[i] );
getchar();
}
while( x >= 0 && x < n && y >= 0 && y < m )
{
step++;
if( vis[x][y] )
{
printf( "%d step(s) before a loop of %d step(s)\n", vis[x][y] - 1, step - vis[x][y] );
flag = 1;
break;
}
vis[x][y] = step;
switch( grid[x][y] )
{
case 'E': y = y + 1; break;
case 'W': y = y - 1; break;
case 'N': x = x - 1; break;
case 'S': x = x + 1; break;
default: break;
}
}
if( !flag )
{
printf( "%d step(s) to exit\n", step );
}
}
return 0;
}