简单模拟题,主要就是判别x和y 在不同方向下的坐标的变化
/*
* Author:lonelycatcher
* Problem:hdu 1035
* Type:模拟,水题
*/
#include<iostream>
#include<stdio.h>
#include<string.h>
using namespace std;
struct node
{
char data;
int visited;
};
node map[10][10];
int row,colum,start;
int main()
{
setbuf(stdout,NULL);
int i,j,x,y,loop,steps;
while(scanf("%d %d %d",&row,&colum,&start)!=EOF)
{
if(!row&&!colum&&!start)break;
for(i=0;i<row;i++)
{
for(j=0;j<colum;j++)
{
cin>>map[i][j].data;
map[i][j].visited=0;
}
}
x=0;y=start-1;loop=0;steps=0;
while(true)
{
steps++;
map[x][y].visited=steps;
if(map[x][y].data=='N')
{
x-=1;
}else if(map[x][y].data=='S')
{
x+=1;
}else if(map[x][y].data=='E')
{
y+=1;
}
else if(map[x][y].data=='W')
{
y-=1;
}
if(x<0||x>=row||y<0||y>=colum)
{
break;
}
if(map[x][y].visited)
{
loop=steps-map[x][y].visited+1;
break;
}
}
if(loop)
{
printf("%d step(s) before a loop of %d step(s)\n",map[x][y].visited-1,loop);
continue;
}
printf("%d step(s) to exit\n",steps);
}
return 0;
}