Advertisement
Guest User

MaxElement

a guest
Jan 20th, 2017
139
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.01 KB | None | 0 0
  1. import java.io.BufferedReader;
  2. import java.io.IOException;
  3. import java.io.InputStreamReader;
  4. import java.util.ArrayDeque;
  5. import java.util.Collections;
  6.  
  7. public class MaxElement {
  8.     public static void main(String[] args) throws IOException {
  9.         BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
  10.         ArrayDeque<Integer> stack = new ArrayDeque<>();
  11.  
  12.         int limit = Integer.parseInt(reader.readLine());
  13.  
  14.         for (int cmdInd = 0; cmdInd < limit; cmdInd++) {
  15.             String line = reader.readLine();
  16.             byte cmd;
  17.             int val;
  18.  
  19.             if (line.length() > 1) {
  20.                 val = Integer.parseInt(line.substring(2));
  21.                 stack.push(val);
  22.             } else {
  23.                 cmd = Byte.parseByte(line);
  24.                 if (cmd == 2) {
  25.                     stack.pop();
  26.                 } else if (cmd == 3) {
  27.                     System.out.println(Collections.max(stack));
  28.                 }
  29.             }
  30.         }
  31.     }
  32. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement