Skip to content

Commit b62a210

Browse files
committed
reverse polish notation
1 parent 87c58cb commit b62a210

File tree

2 files changed

+122
-1
lines changed

2 files changed

+122
-1
lines changed

.vscode/settings.json

Lines changed: 91 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,95 @@
11
{
22
"files.associations": {
3-
"iostream": "cpp"
3+
"iostream": "cpp",
4+
"any": "cpp",
5+
"array": "cpp",
6+
"atomic": "cpp",
7+
"barrier": "cpp",
8+
"bit": "cpp",
9+
"*.tcc": "cpp",
10+
"bitset": "cpp",
11+
"cctype": "cpp",
12+
"cfenv": "cpp",
13+
"charconv": "cpp",
14+
"chrono": "cpp",
15+
"cinttypes": "cpp",
16+
"clocale": "cpp",
17+
"cmath": "cpp",
18+
"codecvt": "cpp",
19+
"compare": "cpp",
20+
"complex": "cpp",
21+
"concepts": "cpp",
22+
"condition_variable": "cpp",
23+
"coroutine": "cpp",
24+
"csetjmp": "cpp",
25+
"csignal": "cpp",
26+
"cstdarg": "cpp",
27+
"cstddef": "cpp",
28+
"cstdint": "cpp",
29+
"cstdio": "cpp",
30+
"cstdlib": "cpp",
31+
"cstring": "cpp",
32+
"ctime": "cpp",
33+
"cuchar": "cpp",
34+
"cwchar": "cpp",
35+
"cwctype": "cpp",
36+
"deque": "cpp",
37+
"forward_list": "cpp",
38+
"list": "cpp",
39+
"map": "cpp",
40+
"set": "cpp",
41+
"string": "cpp",
42+
"unordered_map": "cpp",
43+
"unordered_set": "cpp",
44+
"vector": "cpp",
45+
"exception": "cpp",
46+
"expected": "cpp",
47+
"algorithm": "cpp",
48+
"functional": "cpp",
49+
"iterator": "cpp",
50+
"memory": "cpp",
51+
"memory_resource": "cpp",
52+
"numeric": "cpp",
53+
"optional": "cpp",
54+
"random": "cpp",
55+
"ratio": "cpp",
56+
"regex": "cpp",
57+
"source_location": "cpp",
58+
"string_view": "cpp",
59+
"system_error": "cpp",
60+
"tuple": "cpp",
61+
"type_traits": "cpp",
62+
"utility": "cpp",
63+
"format": "cpp",
64+
"fstream": "cpp",
65+
"future": "cpp",
66+
"initializer_list": "cpp",
67+
"iomanip": "cpp",
68+
"iosfwd": "cpp",
69+
"istream": "cpp",
70+
"latch": "cpp",
71+
"limits": "cpp",
72+
"mutex": "cpp",
73+
"new": "cpp",
74+
"numbers": "cpp",
75+
"ostream": "cpp",
76+
"ranges": "cpp",
77+
"scoped_allocator": "cpp",
78+
"semaphore": "cpp",
79+
"shared_mutex": "cpp",
80+
"span": "cpp",
81+
"spanstream": "cpp",
82+
"sstream": "cpp",
83+
"stacktrace": "cpp",
84+
"stdexcept": "cpp",
85+
"stdfloat": "cpp",
86+
"stop_token": "cpp",
87+
"streambuf": "cpp",
88+
"syncstream": "cpp",
89+
"thread": "cpp",
90+
"typeindex": "cpp",
91+
"typeinfo": "cpp",
92+
"valarray": "cpp",
93+
"variant": "cpp"
494
}
595
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
#include <bits/stdc++.h>
2+
using namespace std;
3+
4+
class Solution {
5+
public:
6+
int evalRPN(vector<string>& tokens) {
7+
stack<int> nums;
8+
for (string s : tokens) {
9+
if (s == "+") {
10+
int a = nums.top(); nums.pop();
11+
int b = nums.top(); nums.pop();
12+
nums.push(b + a);
13+
} else if (s == "-") {
14+
int a = nums.top(); nums.pop();
15+
int b = nums.top(); nums.pop();
16+
nums.push(b - a);
17+
} else if (s == "*") {
18+
int a = nums.top(); nums.pop();
19+
int b = nums.top(); nums.pop();
20+
nums.push(b * a);
21+
} else if (s == "/") {
22+
int a = nums.top(); nums.pop();
23+
int b = nums.top(); nums.pop();
24+
nums.push(b / a);
25+
} else {
26+
nums.push(stoi(s));
27+
}
28+
}
29+
return nums.top();
30+
}
31+
};

0 commit comments

Comments
 (0)