HDU 1035 Robot Motion

很简单的模拟题,只需读懂题就行了
#include<stdio.h>
#include<string.h>
#include<algorithm>
using namespace std;
const int maxm=100;
char map[maxm][maxm];
int vis[maxm][maxm];
int n,m,t;
int main()
{
    while(scanf("%d%d",&m,&n)!=EOF&&(m||n))
    {
        scanf("%d",&t);
        memset(vis,0,sizeof(vis));
        int i,j;
        for(i=0;i<m;i++)
        {
            scanf("%s",map[i]);
        }
        int x=0,y=t-1;
        int ok=0;
        int step=0;
        while(x>=0&&x<m&&y>=0&&y<n)
        {
            if(vis[x][y])
            {
                ok=1;
                break;
            }
            vis[x][y]=++step;
            if(map[x][y]=='W')
            {
                 y--;
            }
            else if(map[x][y]=='S')
            {
                 x++;
            }
            else if(map[x][y]=='E')
            {
                y++;
            }
            else
            {
                x--;
            }
        }
        if(ok)
        {
            printf("%d step(s) before a loop of %d step(s)\n",vis[x][y]-1,step-vis[x][y]+1);
        }
        else
        {
            printf("%d step(s) to exit\n",step);
        }
    }
    return 0;
}

你可能感兴趣的:(HDU 1035 Robot Motion)