forked from mpfeifer1/Kattis
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathturtlemaster.cpp
101 lines (89 loc) · 1.97 KB
/
turtlemaster.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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
#include <iostream>
#include <vector>
#include <string>
using namespace std;
int main() {
vector<vector<char>> v;
v.resize(10, vector<char>(10));
for(int i = 1; i <= 8; i++) {
for(int j = 1; j <= 8; j++) {
cin >> v[i][j];
}
}
string command;
cin >> command;
int dir = 0;
// 0: Right
// 1: Up
// 2: Left
// 3: Down
int x = 1;
int y = 8;
for(auto c : command) {
if(c == 'F') {
if(dir == 0) {
x++;
}
if(dir == 1) {
y--;
}
if(dir == 2) {
x--;
}
if(dir == 3) {
y++;
}
if(x == 0 || x == 9 || y == 0 || y == 9) {
cout << "Bug!" << endl;
return 0;
}
if(v[y][x] == 'C' || v[y][x] == 'I') {
cout << "Bug!" << endl;
return 0;
}
}
if(c == 'L') {
dir++;
dir %= 4;
}
if(c == 'R') {
dir--;
if(dir < 0) {
dir = 3;
}
}
if(c == 'X') {
int tempx = x;
int tempy = y;
if(dir == 0) {
tempx++;
}
if(dir == 1) {
tempy--;
}
if(dir == 2) {
tempx--;
}
if(dir == 3) {
tempy++;
}
if(tempx == 0 || tempx == 9 || tempy == 0 || tempy == 9) {
cout << "Bug!" << endl;
return 0;
}
if(v[tempy][tempx] != 'I') {
cout << "Bug!" << endl;
return 0;
}
else {
v[tempy][tempx] = '.';
}
}
}
if(v[y][x] == 'D') {
cout << "Diamond!" << endl;
}
else {
cout << "Bug!" << endl;
}
}