-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathP10377.cpp
79 lines (70 loc) · 1.46 KB
/
P10377.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
char DIR[4] = {'N', 'E', 'S', 'W'};
int main() {
string maze[66], s, cmd;
int cases, rows, columns, y, x;
getline(cin, s);
stringstream ss1; ss1 << s; ss1 >> cases;
for(int cas = 0; cas < cases; ++cas) {
if(cas != 0)
cout << endl;
getline(cin, s);
getline(cin, s);
stringstream ss2; ss2 << s; ss2 >> rows >> columns;
//cerr << rows << " rows, " << columns << " columns " << endl;
FORI(rows)
getline(cin, maze[i]);
getline(cin, s);
stringstream ss3; ss3 << s; ss3 >> y >> x;
--y; --x;
int dir = 0;
//cerr << y+1 << " " << x+1 << " " << DIR[dir] << endl;
bool done = false;
while(!done) {
getline(cin, cmd);
FORUI(cmd.size()) {
char c = cmd[i];
//cerr << c << " => ";
switch(c) {
case 'R':
++dir;
if(dir == 4)
dir = 0;
break;
case 'L':
--dir;
if(dir == -1)
dir = 3;
break;
case 'F':
switch(dir) {
case 0: // north
if(maze[y-1][x] != '*')
--y;
break;
case 1: // east
if(maze[y][x+1] != '*')
++x;
break;
case 2: // south
if(maze[y+1][x] != '*')
++y;
break;
default: // west
if(maze[y][x-1] != '*')
--x;
break;
}
break;
case 'Q':
cout << y+1 << " " << x+1 << " " << DIR[dir] << endl;
done = true;
break;
default:
break; // space.
}
//cerr << y+1 << " " << x+1 << " " << DIR[dir] << endl;
} // FORUI
} // while(!done)
} // FORCAS
return 0;
}