-
Notifications
You must be signed in to change notification settings - Fork 2
/
q1041.hpp
60 lines (56 loc) · 1.62 KB
/
q1041.hpp
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
//
// q1041.hpp
// LeetCode
//
// Created by 李凌 on 2020/10/9.
// Copyright © 2020 DoubleL. All rights reserved.
//
#ifndef q1041_hpp
#define q1041_hpp
#include <iostream>
#include <queue>
#include <algorithm>
#include <vector>
#include <unordered_map>
#include <unordered_set>
#include <set>
#include <numeric>
#include <stack>
#include <string>
using namespace std;
void question1041(){
class Solution {
public:
bool isRobotBounded(string instructions) {
int directions[4][2] = {{0, 1}, {-1, 0}, {0, -1}, {1, 0}};
int index = 0;
int point[2] = {0, 0};
for (int i = 0; i < 4; i++) {
for (int j = 0; j < instructions.length(); j++) {
switch (instructions[j]) {
case 'G':
point[0] += directions[index][0];
point[1] += directions[index][1];
// printf("%d %d \n", point[0], point[1]);
break;
case 'L':
index = (++index) % 4;
break;
case 'R':
index = (3 + index) % 4;
break;
default:
break;
}
}
}
if (point[0] == 0 && point[1] == 0)
return true;
return false;
}
};
string str = "GGLLGG";
bool result = Solution().isRobotBounded(str);
printf("result %d\n", result);
}
#endif /* q1041_hpp */