-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path751.cpp
More file actions
43 lines (43 loc) · 696 Bytes
/
Copy path751.cpp
File metadata and controls
43 lines (43 loc) · 696 Bytes
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
#include<iostream>
#include<cstring>
#include<stack>
using namespace std;
int main() {
char str[1000];
int ans;
while (cin.getline(str,1000)) {
stack<int> stk;
for (int i = 0; i < strlen(str); i++) {
int x, y;
switch (str[i]) {
case '+':
x = stk.top();
stk.pop();
y = stk.top();
stk.pop();
stk.push(x + y);
break;
case '-':
x = stk.top();
stk.pop();
y = stk.top();
stk.pop();
stk.push(y - x);
break;
case '*':
x = stk.top();
stk.pop();
y = stk.top();
stk.pop();
stk.push(x * y);
break;
case ' ':
break;
default:
stk.push(str[i] - 48);
}
}
cout << stk.top() << endl;
}
return 0;
}