import java.util.*;
public class Postfix{
public static void main(String[] args){
String expression = "5+(4-2)-3*2";
Stack stack = new Stack();
StringBuilder sb = new StringBuilder();
for(int i = 0; i < expression.length(); i++){
char c = expression.charAt(i);
switch(c){
case '0':
case '1':
case '2':
case '3':
case '4':
case '5':
case '6':
case '7':
case '8':
case '9':
sb.append(c);
break;
case '+':
case '-':
case '*':
case '/':
if(!stack.empty() && (stack.peek() != '(')){
if(order(stack.peek()) <= order(c)){
sb.append(stack.pop());
}
}
stack.push(c);
break;
case '(':
stack.push(c);
break;
case ')':
char op;
while((op = stack.pop()) != '('){
sb.append(op);
}
break;
default:
System.out.println("Error");
return;
}
}
while(!stack.empty()){
sb.append(stack.pop());
}
System.out.println(sb.toString());
}
public static int order(char op){
switch(op){
case '*': case '/': return 1;
case '+': case '-': return 2;
default: return 0; }
}
}
}