알고리즘/문제 [BOJ/백준 - 10845] 큐 - 문제 출처: https://www.acmicpc.net/problem/10845 10845번: 큐 첫째 줄에 주어지는 명령의 수 N (1 ≤ N ≤ 10,000)이 주어진다. 둘째 줄부터 N개의 줄에는 명령이 하나씩 주어진다. 주어지는 정수는 1보다 크거나 같고, 100,000보다 작거나 같다. 문제에 나와있지 www.acmicpc.net This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters Show hidden characters public class BOJ_10845 { public static void main(String[] args) throws IOException { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); StringTokenizer st; int len = Integer.parseInt(br.readLine()); ArrayList<Integer> al = new ArrayList<>(); for(int i=0; i<len; i++){ st = new StringTokenizer(br.readLine()); String temp = st.nextToken(); if("pop".equals(temp)){ if(al.isEmpty()){ System.out.println(-1); }else{ System.out.println(al.remove(0)); } }else if("size".equals(temp)){ System.out.println(al.size()); }else if("empty".equals(temp)){ if(al.isEmpty()){ System.out.println(1); }else{ System.out.println(0); } }else if("front".equals(temp)){ if(al.isEmpty()){ System.out.println(-1); }else{ System.out.println(al.get(0)); } }else if("back".equals(temp)){ if(al.isEmpty()){ System.out.println(-1); }else{ System.out.println(al.get(al.size()-1)); } }else{ // push X int num = Integer.parseInt(st.nextToken()); al.add(num); } } } } view raw BOJ_10845.java hosted with ❤ by GitHub 그냥 편하게 어레이리스트 썼다 빨리 풀고 지나가고 싶었음 공유하기 URL 복사카카오톡 공유페이스북 공유엑스 공유 게시글 관리 구독하기Time to lazy Contents 당신이 좋아할만한 콘텐츠 [BOJ/백준 - 1715] 카드 정렬하기 2022.01.13 [BOJ/백준 - 1541] 잃어버린 괄호 2022.01.12 [BOJ/백준 - 15829] Hashing 2022.01.11 [BOJ/백준 - 1744] 수 묶기 2022.01.11 댓글 0 + 이전 댓글 더보기