Advertisement
deyanmalinov

3. Maximum Element 2

Mar 24th, 2020
160
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.73 KB | None | 0 0
  1. package DPM;
  2.  
  3. import java.util.ArrayDeque;
  4. import java.util.Collections;
  5. import java.util.Scanner;
  6.  
  7. public class Main {
  8.     public static void main(String[] args){
  9.         Scanner scan = new Scanner(System.in);
  10.         int comands = Integer.parseInt(scan.nextLine());
  11.         ArrayDeque<Integer> stack = new ArrayDeque<>();
  12.         for (int i = 0; i < comands; i++) {
  13.             String[] line = scan.nextLine().split("\\s+");
  14.             if (Integer.parseInt(line[0])==1){
  15.                 stack.push(Integer.parseInt(line[1]));
  16.             }else if (Integer.parseInt(line[0]) == 2){
  17.                 stack.pop();
  18.             }else {
  19.                 System.out.println(Collections.max(stack));
  20.             }
  21.  
  22.         }
  23.     }
  24. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement