File tree Expand file tree Collapse file tree 3 files changed +109
-1
lines changed Expand file tree Collapse file tree 3 files changed +109
-1
lines changed Original file line number Diff line number Diff line change 59
59
"files.associations" : {
60
60
"*.embeddedhtml" : " html" ,
61
61
"vector" : " cpp" ,
62
- "*.tcc" : " cpp"
62
+ "*.tcc" : " cpp" ,
63
+ "stack" : " cpp"
63
64
}
64
65
}
Original file line number Diff line number Diff line change
1
+ // @before-stub-for-debug-begin
2
+ #include < vector>
3
+ #include < string>
4
+ #include " commoncppproblem657.h"
5
+
6
+ using namespace std ;
7
+ // @before-stub-for-debug-end
8
+
9
+ /*
10
+ * @lc app=leetcode.cn id=657 lang=cpp
11
+ *
12
+ * [657] 机器人能否返回原点
13
+ */
14
+
15
+ // @lc code=start
16
+ class Solution {
17
+ public:
18
+ bool judgeCircle (string moves) {
19
+ int x = 0 ;
20
+ int y = 0 ;
21
+
22
+
23
+ for (auto ch:moves){
24
+ switch (ch)
25
+ {
26
+ case ' U' :
27
+ y++;
28
+ break ;
29
+ case ' D' :
30
+ y--;
31
+ break ;
32
+ case ' L' :
33
+ x--;
34
+ break ;
35
+ case ' R' :
36
+ x++;
37
+ break ;
38
+ default :
39
+ break ;
40
+ }
41
+ }
42
+
43
+ return x==0 && y==0 ;
44
+ }
45
+ };
46
+ // @lc code=end
47
+
Original file line number Diff line number Diff line change
1
+ // @before-stub-for-debug-begin
2
+ #include < vector>
3
+ #include < string>
4
+ #include < stack>
5
+ #include " commoncppproblem682.h"
6
+
7
+ using namespace std ;
8
+ // @before-stub-for-debug-end
9
+
10
+ /*
11
+ * @lc app=leetcode.cn id=682 lang=cpp
12
+ *
13
+ * [682] 棒球比赛
14
+ */
15
+
16
+ // @lc code=start
17
+
18
+
19
+
20
+
21
+ class Solution {
22
+ public:
23
+ int calPoints (vector<string>& operations) {
24
+ stack<string> stk;
25
+ string left = " " ;
26
+ string right = " " ;
27
+
28
+ for (auto op: operations){
29
+ switch (op[0 ])
30
+ {
31
+ case ' C' :
32
+ stk.pop ();
33
+ break ;
34
+ case ' D' :
35
+ left = stk.top ();
36
+ stk.push (to_string (stoi (left) * stoi (left)));
37
+ break ;
38
+ case ' +' :
39
+
40
+ stk.pop ();
41
+ right = stk.pop ();
42
+ stk.push (to_string (stoi (left) + stoi (right)));
43
+ break ;
44
+ default :
45
+ stk.push (op);
46
+ break ;
47
+ }
48
+ }
49
+
50
+ int res = 0
51
+ {
52
+ res+=stoi (stk.top ());
53
+ stk.pop ();
54
+ }
55
+
56
+ return res;
57
+ }
58
+ };
59
+ // @lc code=end
60
+
You can’t perform that action at this time.
0 commit comments