NYOJ 35 表达式求值(二)
ring c = couterFix.top();
double d;
couterFix.pop();
int cas = 5;
if(strcmp(c.c_str(),"+") == 0) cas = 0;
else if(strcmp(c.c_str(),"-") == 0) cas = 1;
else if(strcmp(c.c_str(),"*") == 0) cas = 2;
else if(strcmp(c.c_str(),"/") == 0) cas = 3;
if(cas!=5)
{
double a = resultSta.top();
resultSta.pop();
double b = resultSta.top();
resultSta.pop();
switch(cas)
{
case 0:
{
resultSta.push(b + a);
break;
}
case 1:
{
resultSta.push(b - a);
break;
}
case 2:
{
resultSta.push(b * a);
break;
}
case 3:
{
resultSta.push(b / a);
break;
}
default:
{}
}
}
else
{
sscanf(c.c_str(),"%lf",&d);
resultSta.push(d);
}
}
return resultSta.top();
}
int main()
{
/*#ifndef ONLINE_JUDGE
freopen("in.txt","r",stdin);
#endif*/
int n;
scanf(" %d",&n);
initPri();
while(n--)
{
string infixExp;
stack postfixExp;
cin>>infixExp;
convert(infixExp,postfixExp);
double ans = answerQ(postfixExp);
printf("%.2lf\n",ans);
}
return 0;
}