-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path15815.cpp
60 lines (54 loc) · 1.07 KB
/
15815.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
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
// 15815. 천재 수학자 성필
// 2021.11.10
// 자료구조, 스택
#include<iostream>
#include<stack>
#include<string>
using namespace std;
int main()
{
int ans = 0;
stack<int> st;
string s;
cin >> s;
int a, b;
for (int i = 0; i < s.size(); i++)
{
switch (s[i])
{
case '+':
a = st.top();
st.pop();
b = st.top();
st.pop();
st.push(b + a);
break;
case '-':
a = st.top();
st.pop();
b = st.top();
st.pop();
st.push(b - a);
break;
case '*':
a = st.top();
st.pop();
b = st.top();
st.pop();
st.push(b * a);
break;
case '/':
a = st.top();
st.pop();
b = st.top();
st.pop();
st.push(b / a);
break;
default:
st.push(s[i] - '0');
break;
}
}
cout << st.top() << endl;
return 0;
}