1
class Robot {
2
private:
3
int width, height, perimeter;
4
int dir = 0;
5
int x = 0, y = 0;
6
map<int, string> mp = {{0, "East"}, {1, "North"}, {2, "West"}, {3, "South"}};
7

8
public:
9
Robot(int width, int height) {
10
this->width = width;
11
this->height = height;
12
this->perimeter = 2 * (height + width) - 4;
13
}
14

15
void step(int num) {
16
if (!num) return;
17
num = num % perimeter;
18
if (x == 0 && y == 0 && num == 0) dir = 3;
19
while (num--) {
20
if (x == 0 && y == 0)
21
dir = 0;
22
else if (x == width - 1 && y == 0)
23
dir = 1;
24
else if (x == width - 1 && y == height - 1)
25
dir = 2;
26
else if (x == 0 && y == height - 1)
27
dir = 3;
28

29
if (dir == 0) x += 1;
30
if (dir == 1) y += 1;
31
if (dir == 2) x -= 1;
32
if (dir == 3) y -= 1;
33
}
34
}
35

36
vector<int> getPos() {
37
return {x, y};
38
}
39

40
string getDir() {
41
return mp[dir];
42
}
43
};

0

WPM •0 •0

100%

ACC •0 •0

0s

TIME •0