Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.io.*;
- import java.util.*;
- public class Main {
- static PrintWriter pw;
- public static void main(String[] args) throws FileNotFoundException {
- Scanner in = new Scanner(new File("input.txt"));
- pw = new PrintWriter(new File("output.txt"));
- Stack<Integer> stack = new Stack<>();
- while (in.hasNext()) {
- String a = in.next();
- switch (a){
- case "*":
- stack.push(stack.pop() * stack.pop());
- break;
- case "+":
- stack.push(stack.pop() + stack.pop());
- break;
- case "-":
- stack.push(-stack.pop() + stack.pop());
- break;
- default:
- stack.push(Integer.parseInt(a));
- }
- }
- pw.println(stack.pop());
- pw.close();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement