forked from charlesfranciscodev/codingame
-
Notifications
You must be signed in to change notification settings - Fork 0
/
shadows-knight1.cpp
55 lines (50 loc) · 1.16 KB
/
shadows-knight1.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
#include <iostream>
#include <vector>
using namespace std;
int main() {
int width; // width of the building.
int height; // height of the building.
cin >> width >> height; cin.ignore();
int n;
cin >> n; cin.ignore();
int x, y;
cin >> x >> y; cin.ignore();
int minX = 0;
int maxX = width - 1;
int minY = 0;
int maxY = height - 1;
// game loop
while (true) {
string bombDir;
cin >> bombDir; cin.ignore();
if (bombDir == "U") {
minX = maxX = x;
maxY = y - 1;
} else if (bombDir == "UR") {
minX = x + 1;
maxY = y - 1;
} else if (bombDir == "R") {
minY = maxY = y;
minX = x + 1;
} else if (bombDir == "DR") {
minX = x + 1;
minY = y + 1;
} else if (bombDir == "D") {
minX = maxX = x;
minY = y + 1;
} else if (bombDir == "DL") {
maxX = x - 1;
minY = y + 1;
} else if (bombDir == "L") {
minY = maxY = y;
maxX = x - 1;
} else if (bombDir == "UL") {
maxX = x - 1;
maxY = y - 1;
}
x = (minX + maxX) / 2;
y = (minY + maxY) / 2;
// the location where Batman should jump to.
cout << x << " " << y << endl;
}
}