题目1019:简单计算器
import java.io.BufferedInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.io.StreamTokenizer;
import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;
import java.util.Queue;
import java.util.Scanner;
import java.util.Stack;
public class Main {
public static void main(String[] args) throws IOException {
Scanner cin = new Scanner(new BufferedInputStream(System.in)) ;
PrintWriter cout = new PrintWriter(System.out) ;
String str ;
while(true){
str = cin.nextLine() ;
if(str.equals("0")) break ;
new Task().solve(str, cout);
}
cout.flush() ;
}
}
class Task{
void solve(String str , PrintWriter cout){
String[] oo = str.split(" ") ;
Stack<Double> num = new Stack<Double>() ;
Stack<String> operator = new Stack<String>() ;
operator.add("+") ;
String latest = "+" ;
for(int i = 0 ; i < oo.length ; i++){
String o = oo[i] ;
if("+-*/".contains(o)){
latest = o ;
if(o.equals("+") || o.equals("-"))
operator.add(o) ;
}
else if("*/".contains(latest)){
Double a = num.pop() ;
Double b = Double.parseDouble(o) ;
Double c = null ;
if(latest.equals("*"))
c = a * b ;
else c = a / b ;
num.add(c) ;
}
else num.add(Double.parseDouble(o)) ;
}
double sum = 0 ;
while(! operator.isEmpty()){
if(operator.pop().equals("+")){
sum += num.pop() ;
}
else sum -= num.pop() ;
}
cout.printf("%.2f\n", sum) ;
}
}