회원가입
로그인
Toggle navigation
문제
문제
전체 문제
문제 출처
단계별로 풀어보기
알고리즘 분류
추가된 문제
문제 순위
문제
푼 사람이 한 명인 문제
아무도 못 푼 문제
최근 제출된 문제
최근 풀린 문제
랜덤
출처
ICPC
Olympiad
한국정보올림피아드
한국정보올림피아드시․도지역본선
전국 대학생 프로그래밍 대회 동아리 연합
대학교 대회
카카오 코드 페스티벌
Coder's High
ICPC
Regionals
World Finals
Korea Regional
Africa and the Middle East Regionals
Europe Regionals
Latin America Regionals
North America Regionals
South Pacific Regionals
문제집
대회
1
채점 현황
랭킹
게시판
그룹
더 보기
재채점 기록
블로그
강의
실험실
도움말
BOJ Stack
BOJ Book
전체
공지
자유
질문
오타/오역/요청
게시판 공지
홍보
업데이트
solved.ac
글쓰기
질문 도움말
자주묻는 질문
java// deque관련 질문입니다 ㅠ
10866번 - 덱
na1st
7년 전
0
테스트는 잘되는데 자꾸 틀렷다구하네요.. 어디가 0프로때부터 바로 틀렷다고나오더라구요ㅠㅠㅠㅠㅠㅠㅠ
import java.io.*; import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); sc.nextLine(); int[] stack = new int[10000]; int j, i; int push_num = 0; int rear = n-1; int front = 0; int item_num= 0; if (n >= 1 && n <= 10000) for (i = 0; i < n; i++) { String command = sc.next(); if (command.equals("push_front")) { push_num = sc.nextInt(); stack[front++] = push_num; item_num ++; } else if (command.equals("push_back")) { push_num = sc.nextInt(); stack[rear--] = push_num; item_num ++; } else if (command.equals("pop_front")) { if ((item_num ==0) || (front==0)) System.out.println("-1"); else { System.out.println(stack[--front]); front++; item_num --; } } else if (command.equals("pop_back")) { if ((item_num ==0) || (rear==(n-1))) System.out.println("-1"); else { System.out.println(stack[rear+1]); rear--; item_num --; } } else if (command.equals("size")) { System.out.println(item_num); } else if (command.equals("empty")) { if (item_num==0) System.out.println("1"); else System.out.println("0"); } else if (command.equals("front")) { if(front!=0) System.out.println(stack[front-1]); else System.out.println("-1"); } else if (command.equals("back")) { if(rear!=(n-1)) { System.out.println(stack[rear+1]); } else System.out.println("-1"); } } } }
댓글을 작성하려면
로그인
해야 합니다.
na1st 7년 전
테스트는 잘되는데 자꾸 틀렷다구하네요.. 어디가 0프로때부터 바로 틀렷다고나오더라구요ㅠㅠㅠㅠㅠㅠㅠ