-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhouzhuibiaodashi.cpp
56 lines (56 loc) · 1.16 KB
/
houzhuibiaodashi.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
#include <iostream>
#include <cstdio>
#include <stack>
using namespace std;
stack <int> s;
int aa[5];
int sum;
int main(){
char a;
int now=0;
while((a=getchar())!='@') {
if (a >= '0' && a <= '9') {
now*=10;
now+=a-'0';
} else if (a == '.') {
s.push(now);
now=0;
continue;
} else {
if (a == '+') {
aa[1] = s.top();
s.pop();
aa[2] = s.top();
s.pop();
sum = aa[2] + aa[1];
s.push(aa[2] + aa[1]);
}
if (a == '-') {
aa[1] = s.top();
s.pop();
aa[2] = s.top();
s.pop();
sum = aa[2] - aa[1];
s.push(aa[2] - aa[1]);
}
if (a == '*') {
aa[1] = s.top();
s.pop();
aa[2] = s.top();
s.pop();
sum = aa[2] * aa[1];
s.push(aa[2] * aa[1]);
}
if (a == '/') {
aa[1] = s.top();
s.pop();
aa[2] = s.top();
s.pop();
sum = aa[2] / aa[1];
s.push(aa[2] / aa[1]);
}
}
}
cout<<sum<<endl;
return 0;
}