-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path1121.cpp
More file actions
97 lines (78 loc) · 2.36 KB
/
1121.cpp
File metadata and controls
97 lines (78 loc) · 2.36 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
#include <iostream>
#include <vector>
#include <map>
using namespace std;
struct turn {
char left;
char right;
};
map<char, turn> todo = {
{'N', {'O', 'L'}},
{'S', {'L', 'O'}},
{'L', {'N', 'S'}},
{'O', {'S', 'N'}}
};
map<char, pair<int,int>> toMove = {
{'N', {-1, 0}},
{'S', {1, 0}},
{'L', {0, 1}},
{'O', {0, -1}}
};
vector<char> directions = {'N', 'S', 'L', 'O'};
bool contains(const vector<char>& directions, char c) {
for (auto d : directions) {
if (c == d) return true;
}
return false;
}
int main() {
int linha, coluna, instr;
while (cin >> linha >> coluna >> instr) {
if (linha == 0 && coluna == 0 && instr == 0)
break;
vector<vector<char>> arena(linha, vector<char>(coluna));
int cont = 0;
char celula;
char dirAtual;
char instruction;
pair<int,int> posAtual;
pair<int,int> newPos;
for (int i=0; i<linha; i++) {
for (int j=0; j<coluna; j++) {
cin >> celula;
arena[i][j] = celula;
if (contains(directions, celula)) {
dirAtual = celula;
posAtual.first = i;
posAtual.second = j;
arena[i][j] = '.';
}
}
}
for (int s=0; s<instr; s++) {
cin >> instruction;
if (instruction == 'D') {
dirAtual = todo[dirAtual].right;
} else if (instruction == 'E') {
dirAtual = todo[dirAtual].left;
} else if (instruction == 'F') {
newPos = {posAtual.first + toMove[dirAtual].first,
posAtual.second + toMove[dirAtual].second};
if (newPos.first < 0 || newPos.second < 0 || newPos.first >= linha || newPos.second >= coluna ) {
continue;
}
if (arena[newPos.first][newPos.second] == '#') {
continue;
} else {
posAtual = newPos;
if (arena[newPos.first][newPos.second] == '*') {
cont++;
arena[newPos.first][newPos.second] = '.';
}
}
}
}
cout << cont << endl;
}
return 0;
}