#include<iostream>
#include<iomanip>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<fstream>
using namespace std;
int r[2][197],rr=0,a,c,b,d,nd;
int dont(int x,int y){
for(int xx=0;xx<rr;xx++){
if(x==r[0][xx]&&y==r[1][xx]){
return 1;
}
}
return 0;
}
int dontgo(int x,int y){
if(x<0){
c++;
}
if(y<0){
d++;
}
if(x>a){
c--;
}
if(y>b){
d--;
}
}
int main(){
char e,s[101];
bool l;
cin>>a>>b;
while(cin>>c>>d>>e>>s){
l=0;
if(e=='N'){
nd=0;
}else if(e=='S'){
nd=2;
}else if(e=='E'){
nd=1;
}else if(e=='W'){
nd=3;
}
for(int x=0;x<strlen(s);x++){
if(s[x]=='F'){
if(nd==0){
if(dont(c,d)){
d++;
dontgo(c,d);
}else{
d++;
}
}else if(nd==1){
if(dont(c,d)){
c++;
dontgo(c,d);
}else{
c++;
}
}else if(nd==2){
if(dont(c,d)){
d--;
dontgo(c,d);
}else{
d--;
}
}else if(nd==3){
if(dont(c,d)){
c--;
dontgo(c,d);
}else{
c--;
}
}
}else if(s[x]=='R'){
nd++;
}else if(s[x]=='L'){
nd--;
}
if(nd>3){
nd=0;
}
if(nd<0){
nd=3;
}
if(d<0||c<0||c>a||d>b){
l=1;
dontgo(c,d);
r[0][rr]=c;
r[1][rr]=d;
rr++;
break;
}
}
cout<<c<<" "<<d<<" ";
if(nd==0){
cout<<"N";
}else if(nd==1){
cout<<"E";
}else if(nd==2){
cout<<"S";
}else if(nd==3){
cout<<"W";
}
if(l==1){
cout<<" LOST";
}
cout<<endl;
}
system("pause");
return 0;
}
沒有留言:
張貼留言