반응형
Recent Posts
Recent Comments
관리 메뉴

개발잡부

[groom] Queue 본문

이직/groom

[groom] Queue

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

package kr.co.doo.cote.groom;

import java.io.*;

import java.util.LinkedList;
import java.util.Queue;
import java.util.StringTokenizer;

public class Queuee {

    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 qSize = Integer.parseInt(st.nextToken());
        Queue<String> queue = new LinkedList<>();

        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 (queue.size() == 0 && cmd.equals("pop")) {
                System.out.println("Underflow");
            } else if (cmd.equals("pop")) {
                System.out.println(queue.poll());
            }
            if (queue.size() >= qSize && cmd.equals("push")) {
                System.out.println("Overflow");
            } else if (cmd.equals("push")) {
                queue.add(num);
            }
        }
    }
}
반응형

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

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