반응형
Recent Posts
Recent Comments
관리 메뉴

개발잡부

[groom] Stack 본문

이직/groom

[groom] Stack

닉의네임 2023. 5. 15. 10:22
반응형

package kr.co.doo.cote.groom;

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Stack;
import java.util.StringTokenizer;

public class Stackk {
    public static void main(String[] args) throws Exception {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        StringTokenizer st = new StringTokenizer(br.readLine());
        int end = Integer.parseInt(st.nextToken());
        int sSize = Integer.parseInt(st.nextToken());
        Stack<String> stack = new Stack<>();

        for (int i = 0; i < end; i++) {
            StringTokenizer stringTokenizer = new StringTokenizer(br.readLine());
            String cmd = stringTokenizer.nextToken();
            String num = "";
            if (stringTokenizer.hasMoreTokens()) {
                num = stringTokenizer.nextToken();
            }

            if (stack.size() == 0 && cmd.equals("pop")) {
                System.out.println("Underflow");
            } else if (cmd.equals("pop")) {
                System.out.println(stack.pop());
            }
            if (stack.size() >= sSize && cmd.equals("push")) {
                System.out.println("Overflow");
            } else if (cmd.equals("push")) {
                stack.push(num);
            }
        }
    }
}
반응형

'이직 > groom' 카테고리의 다른 글

[groom] M배 배열  (0) 2023.05.15
[groom] Queue  (0) 2023.05.15
[groom] 8진수 계산기  (0) 2023.05.15
[groom] 수열 - 피보나치의 수  (0) 2023.05.13
[groom] 거스름돈  (0) 2023.05.10
Comments