-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathp1041.cpp
35 lines (33 loc) · 1.01 KB
/
p1041.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
#include <bits/stdc++.h>
using namespace std;
class Solution {
public:
bool isRobotBounded(string instructions) {
pair<int, int> coordinates;
int rotation = 0;
for(char c : instructions) {
if(c == 'L') {
--rotation;
} else if(c == 'R') {
++rotation;
} else if(c == 'G') {
while(rotation < 0) {
rotation += 4;
}
rotation = rotation % 4;
switch(rotation) {
case 0 : ++coordinates.second;
break;
case 1 : ++coordinates.first;
break;
case 2 : --coordinates.second;
break;
case 3 : --coordinates.first;
break;
}
}
}
bool zero = coordinates.first == 0 && coordinates.second == 0;
return (rotation != 0 && (!zero)) || (zero);
}
};