// @BEGIN_OF_SOURCE_CODE /* @JUDGE_ID: 17243NT 118 C++ "Transformers... robots in the skies" */ // Send to judge@uva.es #include #include #ifdef ONLINE_JUDGE #define ins cin #define outs cout #else #define ins fin #define outs fout ifstream fin("myprog.in"); ofstream fout("myprog.out"); #endif bool scent[51][51]; int w, h, x, y; int dir; int main() { char inst[120], d; int i; bool lost; ins >> w >> h; while(ins >> x >> y >> d) { if(d == 'E') dir = 0; if(d == 'N') dir = 1; if(d == 'W') dir = 2; if(d == 'S') dir = 3; ins >> inst; lost = false; for(i = 0; inst[i]; i++) { if(inst[i] == 'L') dir = (dir + 1) % 4; if(inst[i] == 'R') dir = (dir + 3) % 4; if(inst[i] == 'F') { int cx = x, cy = y; if(dir == 0) x++; if(dir == 1) y++; if(dir == 2) x--; if(dir == 3) y--; if(x < 0 || x > w || y < 0 || y > h) { x = cx, y = cy; if(!scent[x][y]) { scent[x][y] = true; lost = true; break; } } } } cout << x << ' ' << y << ' '; if(dir == 0) cout << 'E'; if(dir == 1) cout << 'N'; if(dir == 2) cout << 'W'; if(dir == 3) cout << 'S'; if(lost) cout << " LOST"; cout << endl; } return 0; } // @END_OF_SOURCE_CODE