import java.util.*; import java.io.*; // REVATHY PILLAI COMPVIZ JUNIOR public class ACSLrealTest4 { public static void main(String[] argv) { Scanner kbReader = new Scanner(System.in); int maxInputs = 5; String[] inputsPattern = new String[maxInputs]; for (int i = 0; i < maxInputs; i++) { inputsPattern[i] = kbReader.nextLine(); } for (int i = 0; i < maxInputs; i++) { PrefixOrder(inputsPattern[i]); } } private static void PrefixOrder(String inputExpression) { inputExpression = new StringBuffer(inputExpression).reverse().toString(); String temp = ""; StringTokenizer tokenizer = new StringTokenizer(inputExpression, "+ - *", true); Stack operand = new Stack(); Stack operator = new Stack(); while (tokenizer.hasMoreTokens()) { temp = tokenizer.nextToken(); if (temp.compareTo("+") == 0 || temp.compareTo("-") == 0 || temp.compareTo("*") == 0) { operator.push((String) temp); } else { operand.push((String) temp); } } String strOperator = ""; String strOldOperator = ""; boolean isOperatorEmpty = false; boolean isOperandEmpty = false; String strOutput = ""; while (!isOperatorEmpty || !isOperandEmpty) { if (!operator.isEmpty()) { if (!strOperator.equals("")) strOldOperator = strOperator; strOperator = (String) operator.pop(); if (strOperator.equals("+")) strOutput = strOperator + strOutput; if (strOperator.equals("-")) strOutput = strOperator + strOutput; if (strOperator.equals("*")) strOutput = strOutput + strOperator; } else isOperatorEmpty = true; if (!isOperatorEmpty && strOperator.equals("*")) { continue; } if (!operand.isEmpty()) { strOutput = strOutput + (String) operand.pop(); if (!operand.isEmpty() && strOldOperator.equals("*")) strOutput = strOutput + (String) operand.pop(); } else isOperandEmpty = true; } System.out.println(strOutput); } }