this is my code:
Code: Select all
#include <iostream.h>
#include <string.h>
int n,m,x,y,d[3];
char movelist[200];
bool scent[51][51];
char direction()
{
if (d[1]== 1)
return 'N';
else if (d[1]==-1)
return 'S';
else if (d[0]== 1)
return 'E';
else
return 'W';
}
bool move(char mo)
{
int temp;
bool sw=true;
if (mo=='F')
{
x+=d[0];
y+=d[1];
if (x>n||x<0||y<0||y>m)
{
x-=d[0];
y-=d[1];
if (scent[x][y])
{
scent[x][y]=false;
sw=false;
}
}
}
else if (mo=='R')
{
temp=d[0];
d[0]=d[1];
d[1]=-temp;
}
else if (mo=='L')
{
temp=d[1];
d[1]=d[0];
d[0]=-temp;
}
return sw;
}
void main()
{
int i,j;
char dir;
bool sw;
for (i=0;i<51;i++)
for (j=0;j<51;j++)
scent[i][j]=true;
cin >>n>>m;
while (cin>>x>>y>>dir)
{
if (dir=='N') {d[0]= 0;d[1]= 1;}
else if(dir=='E') {d[0]= 1;d[1]= 0;}
else if(dir=='S') {d[0]= 0;d[1]=-1;}
else if(dir=='W') {d[0]=-1;d[1]= 0;}
cin.getline(movelist,100,'\n');
cin.getline(movelist,100,'\n');
sw=true;
for (i=0;i<strlen(movelist)&&sw;i++)
sw=move(movelist[i]);
if (sw)
cout<<x<<" "<<y<<" "<<direction()<<endl;
else
cout<<x<<" "<<y<<" "<<direction()<<" LOST\n";
}
}
