#include <iostream>
#include<iomanip>
#include <string>
#include <sstream>
#include<queue>
using namespace std;
bool fun(char a){
  if(a=='*'||a=='/')
      return true;
  return false;
}
double fun1(double i,double j,char a)
{
  if(a=='*')
      return i*j;
  else if(a=='/')
  {  return (i*1.0)/j;}
  else if(a=='+')
      return i+j;
  else return i-j;

}
int main()
{
    deque<double>x;
    deque<char>s1;
    string line;

//    freopen("testdata.txt","rt",stdin);

    while(getline(cin,line) && line!="0")
    {
        
        istringstream sin(line);
        x.clear();
        s1.clear();
        double a;
        char c;
        while(sin>>a>>c)
        {
            x.push_back(a);
            s1.push_back(c);
            
        }
        
        sin>>a;
        
        x.push_back(a);
        
        char temp,back;
        double i,j,n;
        while(!s1.empty()){
            
        temp=s1.front();
        //cout<<"temp::"<<temp<<endl;
        s1.pop_front();
        if(fun(temp)||s1.empty())
        { i=x.front();x.pop_front();j=x.front();x.pop_front();
         x.push_front(fun1(i,j,temp));  }
        else{
            back=s1.front();s1.pop_front();
            
            if(fun(back))
            {n=x.front();x.pop_front();i=x.front();x.pop_front();j=x.front();x.pop_front();
             x.push_front(fun1(i,j,back));x.push_front(n);s1.push_front(temp);}
            else{
             i=x.front();x.pop_front();j=x.front();x.pop_front();x.push_front(fun1(i,j,temp));
             s1.push_front(back);}            
            }    
            
        }

        i=x.front();
        cout<<fixed<<showpoint<<setprecision(2)<<i<<endl;
        
        
        
        //cout<<a;
    }
    return 0;
    
}

posted on 2013-02-25 19:47  叶城宇  阅读(401)  评论(0编辑  收藏  举报