该楼层疑似违规已被系统折叠 隐藏此楼查看此楼
#include
#include
#include
#include
#include
#include
using namespace std;
vector > f(string s)//��stringת��Ϊvector
{
vector > v;
char ch[100];
string str;
int i=0, j;
while (s[i] != '\0')
{
if (s[i] == '(')
{
str = s[i++] + '\0';
v.push_back(make_pair (1, str));
}
else if (s[i] == ')')
{
str = s[i++] + '\0';
v.push_back(make_pair < int, string>(2, str));
}
else if (s[i] == '+' || s[i] == '-')
{
str = s[i++] + '\0';
v.push_back(make_pair < int, string>(3, str));
}
else if (s[i] == '*' || s[i] == '/')
{
str = s[i++] + '\0';
v.push_back(make_pair < int, string>(4, str));
}
else if(s[i] == ' ')
{
i++;
continue;
}
else if (s[i] <= '9' && s[i] >= '0' || s[i] == '.')
{
bool dian;
if(s[i] == '.')
dian = true;
j = 1;
ch[0] = s[i++];
int k = 1;
while(s[i] <= '9' && s[i] >= '0' || s[i] == '.')
{
if(s[i] == '.' && dian)
{
cout<
while(1);
}
ch[j] = s[i];
++j;
++i;
}
ch[j] = '\0';
v.push_back(make_pair < int, string >(0, ch));
dian = false;
}
}
return v;
}
bool bijiao(int n, string a)
{
int m;
if(a == "+" || a == "-")
m=3;
else if(a == "*" || a == "/")
m=4;
else if(a == "#")
m=-1;
return n>m?true:false;
}
stack f_nbl(vector > v)
{
stack s, f;
f.push("#");
for(vector >::iterator xi = v.begin(); xi != v.end(); ++xi)
{
if(xi->first == 0)
s.push(xi->second);
else
{
if(xi->first == 1)
f.push(xi->second);
else if(xi->first == 2)
{
while(f.top() != "(")
{
s.push(f.top());
f.pop();
}
f.pop();
}
else if(f.top() == "(")
f.push(xi->second);
else
{
if(f.top() == "#")
{
f.push(xi->second);
}
else
{
if(bijiao(xi->first, f.top()))
f.push(xi->second);
else
{
while(!bijiao(xi->first, f.top()))
{
s.push(f.top());
f.pop();
}
f.push(xi->second);
}
}
}
}
}
while(f.top() != "#")
{
s.push(f.top());
f.pop();
}
f.pop();
while(!s.empty())
{
f.push(s.top());
s.pop();
}
return f;
}
double f_js(stack s)
{
double a, b;
string ch;
stack p;
while(!s.empty())
{
while(s.top() != "+" && s.top() != "-" && s.top() != "*" && s.top() != "/")
{
//p.push((int)(s.top() - '0'));
p.push(atof(s.top().c_str()));
s.pop();
}
ch = s.top();
s.pop();
b = p.top();
p.pop();
a = p.top();
p.pop();
switch(ch[0])
{
case '+' : p.push(a + b); break;
case '-' : p.push(a - b); break;
case '*' : p.push(a * b); break;
case '/' : if(b==0.0)
{
cout<
while(1);
}
else
p.push(a / b);
break;
}
}
return p.top();
}
int main()
{
string s;
cout<
cin>>s;
cout<
return 0;
}