-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path7-7 后缀式求值 (25分).cpp
85 lines (64 loc) · 1.07 KB
/
7-7 后缀式求值 (25分).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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
#include<iostream>
#include<stack>
#include<string>
#include<sstream>
#include<map>
using namespace std;
stack<double> s;
map<char ,int> Map;
void init(){
Map['+']=0;
Map['-']=0;
Map['*']=1;
Map['/']=1;
Map['(']=-1;
}
int main(){
string str;
getline(cin,str);
istringstream strt(str);
int len=str.length();
double res=0;
string t;
strt>>t;
while(t.length()>0){
// cout<<"t="<<t<<endl;
if(t.length()==1&&(t=="*"||t=="/"||t=="+"||t=="-")){
double b=s.top();
cout<<"b="<<b<<endl;
s.pop();
double a=s.top();
cout<<"a="<<a<<endl;
s.pop();
if(t=="+"){
s.push(a+b);
}
else if(t=="-"){
s.push(a-b);
}
else if(t=="*"){
s.push(a*b);
}
else if(t=="/"){
s.push(a/b);
}
}else{
// char *tt=t.;
stringstream strs(t);
double tin;
strs>>tin;
s.push(tin);
}
cout<<"t.top()="<<s.top()<<endl;
t="";
strt>>t;
}
printf("%.1lf",s.top());
// istringstream ss("123 23 4");
//
//// cout<<ss.str()<<endl;
// string a;
// ss>>a;
// cout<<a<<endl;
return 0;
}