forked from mpfeifer1/Kattis
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpathtracing.cpp
77 lines (67 loc) · 1.51 KB
/
pathtracing.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
#include <iostream>
#include <vector>
using namespace std;
int main() {
// Setup
vector<string> v = {"*"};
int x = 0, y = 0;
int startx = 0, starty = 0;
string s;
// For each command
while(cin >> s) {
// Go down
if(s == "down") {
y++;
if(y >= v.size()) {
string temp(v[0].size(), ' ');
v.push_back(temp);
}
}
// Go up
if(s == "up") {
y--;
if(y < 0) {
starty++;
y++;
string temp(v[0].size(), ' ');
v.insert(v.begin(), temp);
}
}
// Go left
if(s == "left") {
x--;
if(x < 0) {
startx++;
x++;
for(auto& i : v) {
i.insert(i.begin(), ' ');
}
}
}
// Go right
if(s == "right") {
x++;
if(x >= v[0].size()) {
for(auto& i : v) {
i.push_back(' ');
}
}
}
v[y][x] = '*';
}
// Get Start and End positions
v[y][x] = 'E';
v[starty][startx] = 'S';
// Pad with '#'
for(auto& i : v) {
i.insert(i.begin(), '#');
i.push_back('#');
}
string temp(v[0].size(), '#');
v.insert(v.begin(), temp);
v.push_back(temp);
// Print answer
for(auto str : v) {
cout << str << endl;
}
}