Saturday, September 17, 2016

UVA 118 - Mutant Flatworld Explorers

#include<bits/stdc++.h>
using namespace std;
bool destination, flg[100][100];
int nx , ny, row , col;
char orientation;
void process(char x)
{
if(orientation == 'S' && x == 'R')orientation = 'W';
else if(orientation == 'S' && x == 'L')orientation = 'E';
else if(orientation == 'N' && x == 'R')orientation = 'E';
else if(orientation == 'N' && x == 'L')orientation = 'W';
else if(orientation == 'E' && x == 'R')orientation = 'S';
else if(orientation == 'E' && x == 'L')orientation = 'N';
else if(orientation == 'W' && x == 'R')orientation = 'N';
else if(orientation == 'W' && x == 'L')orientation = 'S';
if(x == 'F'){
switch(orientation){
case 'N':
if(row == ny && flg[nx][ny])break;
else if(row == ny && !flg[nx][ny]){
flg[nx][ny] = true;
cout<<nx<<' '<<ny<<' '<<orientation<<" LOST\n";
destination = true;
break;
}
ny++;
break;
case 'S':
if(ny == 0 && flg[nx][ny])break;
else if(ny == 0 && !flg[nx][ny]){
flg[nx][ny] = true;
cout<<nx<<' '<<ny<<' '<<orientation<<" LOST\n";
destination = true;
break;
}
ny--;
break;
case 'E':
if(col == nx && flg[nx][ny])break;
else if(col == nx && !flg[nx][ny]){
flg[nx][ny] = true;
cout<<nx<<' '<<ny<<' '<<orientation<<" LOST\n";
destination = true;
break;
}
nx++;
break;
case 'W':
if(nx == 0 && flg[nx][ny])break;
else if(nx == 0  && !flg[nx][ny]){
flg[nx][ny] = true;
cout<<nx<<' '<<ny<<' '<<orientation<<" LOST\n";
destination = true;
break;
}
nx--;

}
}
}

int main()
{
memset(flg,false,sizeof flg);
cin>>col>>row;
while(cin>>nx>>ny>>orientation){
char com[100];
cin>>com;
destination = false;
for(int i = 0; com[i] && !destination; i++){
process(com[i]);
}
if(!destination)cout<<nx<<' '<<ny<<' '<<orientation<<'\n';
}

return 0;
}

No comments:

Post a Comment