-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathuva-10377.cpp
More file actions
107 lines (91 loc) · 1.51 KB
/
uva-10377.cpp
File metadata and controls
107 lines (91 loc) · 1.51 KB
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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
//uva 10377
//Maze Traversal
#include <iostream>
#include <vector>
using namespace std;
char rotateR(char d);
char rotateL(char d);
int main(void)
{
int T = 0;
cin >> T;
while (T--) {
int n, m;
cin >> n >> m;
getchar();
vector < string > maze;
for (int i = 0; i < n; ++i){
string tmp;
getline(std::cin, tmp);
maze.push_back(tmp);
}
int x, y;
char direct = 'N';
cin >> x >> y;//assumming bounds are given from zero if not, decrease them by one
--x;
--y;
bool finished = 0;
while(!finished){
string move;
cin >> move;
for (auto a : move)
switch(a){
case 'R':
direct = rotateR(direct);
break;
case 'L':
direct = rotateL(direct);
break;
case 'F':{
int xp = x;
int yp = y;
if (direct == 'N')
xp -= 1;
if (direct == 'E')
yp += 1;
if (direct == 'S')
xp += 1;
if (direct == 'W')
yp -= 1;
if (xp >= 0 && yp >= 0 && xp < n && yp < m)
if (maze[xp][yp] == ' '){
x = xp;
y = yp;
}
break;
}
case 'Q':
finished = 1;
break;
default:
break;
}
}
cout << x + 1 << ' ' << y + 1 << ' ' << direct << endl;
if (T)
cout << endl;
}
return 0;
}
char rotateR(char d)
{
if (d == 'N')
return 'E';
if (d == 'E')
return 'S';
if (d == 'S')
return 'W';
else
return 'N';
}
char rotateL(char d)
{
if (d == 'N')
return 'W';
if (d == 'W')
return 'S';
if (d == 'S')
return 'E';
else
return 'N';
}