首页 > 代码库 > poj1573

poj1573

//纯模拟 
#include<iostream>
#include<cstring>
using namespace std;
struct node
{
	char direction;
	int step;
};
node map[11][11];
int main()
{
	int row,column,enter,step,i,j,v[11][11],x,y;
	while(scanf("%d%d%d",&row,&column,&enter)&&(row!=0||column!=0||enter!=0))
	{
		memset(v,0,sizeof(v));
		getchar();
		for(i=1;i<=row;i++)
		{
			for(j=1;j<=column;j++)
			scanf("%c",&map[i][j].direction);
			getchar();
		}
		x=1;
		y=enter;
		step=0;
		while(0<x&&x<=row&&0<y&&y<=column&&v[x][y]==0)
		{
			v[x][y]=1;
			step++;
			map[x][y].step=step;
			if(map[x][y].direction==‘E‘)
			y++;
			else if(map[x][y].direction==‘S‘)
			x++;
			else if(map[x][y].direction==‘W‘)
			y--;
			else
			x--;
		}
		if(x<=0||y<=0||x>row||y>column)
		printf("%d step(s) to exit\n",step);
		else
		printf("%d step(s) before a loop of %d step(s)\n",map[x][y].step-1,step-map[x][y].step+1);
	}
}