forked from moranzcw/LeetCode-NOTES
-
Notifications
You must be signed in to change notification settings - Fork 0
/
solution.cpp
34 lines (34 loc) · 983 Bytes
/
solution.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
class Solution
{
public:
int evalRPN(vector<string>& tokens)
{
stack<int> fuckYou;
for(int i=0;i<tokens.size();i++)
{
if(tokens[i] != "+" && tokens[i] != "-" && tokens[i] != "*" && tokens[i] != "/")
{
stringstream ss(tokens[i]);
int temp;
ss >> temp;
fuckYou.push(temp);
}
else
{
int b = fuckYou.empty()? 0:fuckYou.top();
fuckYou.pop();
int a = fuckYou.empty()? 0:fuckYou.top();
fuckYou.pop();
if(tokens[i] == "+")
fuckYou.push(a+b);
if(tokens[i] == "-")
fuckYou.push(a-b);
if(tokens[i] == "*")
fuckYou.push(a*b);
if(tokens[i] == "/")
fuckYou.push(a/b);
}
}
return fuckYou.top();
}
};