/* package whatever; // don't place package name! */

import java.util.*;
import java.lang.*;
import java.io.*;

import java.util.Scanner;

class LinkedStack {

	public class StackNode{
		int data;
		StackNode link;
	}
	private StackNode top;

	public boolean isEmpty(){
		return (top == null);
	}

	public void push(int item){
		StackNode newNode = new StackNode();
		newNode.data = item;
		newNode.link = top;
		top = newNode;
	}

	public int pop() throws IntegerStackEmptyException{
		if(isEmpty()){
			throw new IntegerStackEmptyException("수식 형식이 잘못되었습니다.");
		}
		else{
			int item = top.data;
			top = top.link;
			return item;
		}
	}
	public class IntegerStackEmptyException extends Exception {
		public IntegerStackEmptyException(String message) {
			super(message);
		}
	}

	public static class PostFix {

		private String exp;

		public int evalPostfix(String postfix) throws IntegerStackEmptyException{
			LinkedStack s= new LinkedStack();
			exp = postfix;
			int op1,op2,value;
			char testCh;
			for(int i=0; i<7;i++){
				testCh = exp.charAt(i);
				if(testCh !='+' && testCh != '-' &&
						testCh!='*' && testCh !='/'){
					value = testCh - '0';
					s.push(value);
				}
				else{
					op2 = s.pop();
					op1 = s.pop();
					switch(testCh){
					case'+' : s.push(op1 + op2); break;
					case'-' : s.push(op1 - op2); break;
					case'*' : s.push(op1 * op2); break;
					case'/' : s.push(op1 / op2); break;
					}
				}

			}
			return s.pop();	
		}
		public static void main(String[] args) throws IntegerStackEmptyException{
			// TODO Auto-generated method stub


			Scanner scan = new Scanner(System.in);
			PostFix o = new PostFix();

			System.out.print("후위 표기정수 수식 입력:");
			String result = scan.next();

			System.out.println("결과: "+o.evalPostfix(result));
		}

	}
}