📄 1165.cpp
字号:
/* This Code is Submitted by wywcgs for Problem 1165 on 2006-02-25 at 01:40:48 */
#include <cstdio>
#include <cstring>
const int MAX = 64;
const char *DIR_O = "NESW";
const int DIR[][2]= { { 0, 1 }, { 1, 0 }, { 0, -1 }, { -1, 0 } };
int w, h;
bool dis[MAX][MAX];
inline bool legal(int x, int y) { return (x >= 0 && y >= 0 && x <= w && y <= h); }
int main()
{
int x, y;
char d, intro[128];
memset(dis, false, sizeof(dis));
scanf("%d %d", &w, &h);
while(scanf("%d %d %c %s", &x, &y, &d, intro) != EOF) {
bool lost = false;
int i, o;
for(o = 0; DIR_O[o] != d; o++) ;
for(i = 0; intro[i] != 0 && !lost; i++) {
switch(intro[i]) {
case 'L': o = (o-1)&3; break;
case 'R': o = (o+1)&3; break;
case 'F':
int cx = x+DIR[o][0], cy = y+DIR[o][1];
if(!legal(cx, cy)) { lost = !dis[x][y]; dis[x][y] = true; }
else x = cx, y = cy;
break;
}
}
printf("%d %d %c%s\n", x, y, DIR_O[o], lost ? " LOST" : "");
}
return 0;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -