Download as txt, pdf, or txt
Download as txt, pdf, or txt
You are on page 1of 2

#include <bits/stdc++.

h>
using namespace std;

int main() {
int a, b;
cin >> a >> b;

char di[4] = {'N', 'E', 'S', 'W'};


map <int, pair<int, int>> dice;
dice[0].first = 0;
dice[0].second = 1; // n
dice[1].first = 1;
dice[1].second = 0; // e
dice[2].first = 0;
dice[2].second = -1; // s
dice[3].first = -1;
dice[3].second = 0; // w

int lost, flag[a + 1][b + 1];

for (int i=0; i<a + 1; i++) {


for (int j=0; j<b + 1; j++) {
flag[i][j] = 0;
}
}

int x, y, d;
char c;

while (cin >> x >> y >> c) {


lost = 0;
if (c == 'N') {
d = 0;
} else if (c == 'E') {
d = 1;
} else if (c == 'S') {
d = 2;
} else if (c == 'W') {
d = 3;
}
cin.ignore();
string str;
getline(cin, str);

for (int i=0; i<str.length(); i++) {


if (lost == 0) {
if (str[i] == 'R'){
d = (d+1)%4;
} else if (str[i] == 'L') {
d = (d+3)%4;
} else if (str[i] == 'F') {
x += dice[d].first;
y += dice[d].second;

if (x > a || x < 0 || y > b || y < 0) {


x -= dice[d].first;
y -= dice[d].second;

if (flag[x][y] == 0) { //錯的就不能再錯了
lost = 1;
flag[x][y] = 1;
}
}
}
}

cout << x << " " << y << " " << di[d];
if (lost == 1) {
cout << " LOST";
}
cout << endl;

return 0;
}

You might also like