Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.io.BufferedReader;
- import java.io.IOException;
- import java.io.InputStreamReader;
- import java.util.ArrayDeque;
- import java.util.Collections;
- public class MaxElement {
- public static void main(String[] args) throws IOException {
- BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
- ArrayDeque<Integer> stack = new ArrayDeque<>();
- int limit = Integer.parseInt(reader.readLine());
- for (int cmdInd = 0; cmdInd < limit; cmdInd++) {
- String line = reader.readLine();
- byte cmd;
- int val;
- if (line.length() > 1) {
- val = Integer.parseInt(line.substring(2));
- stack.push(val);
- } else {
- cmd = Byte.parseByte(line);
- if (cmd == 2) {
- stack.pop();
- } else if (cmd == 3) {
- System.out.println(Collections.max(stack));
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement