회원가입
로그인
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
문제집
대회
채점 현황
게시판
그룹
더 보기
재채점 기록
블로그
도움말
전체
공지
자유
질문
오타/오역/요청
게시판 공지
홍보
업데이트
solved.ac
글쓰기
질문 도움말
자주묻는 질문
고수님들 도와주십쇼ㅜㅜ
12789번 - 도키도키 간식드리미
wodnr54071
2년 전
0
어떤 부분이 틀렸는지 잘 모르겠습니다..
import java.util.*; import java.io.*; public class Main { private int [] arr; private int num; private int capacity; public class EmptyIntStackException extends RuntimeException{ EmptyIntStackException(){} } public class OverflowIntStackException extends RuntimeException{ OverflowIntStackException(){} } public Main(int n) { capacity = n; num = 0; try { arr = new int[capacity]; }catch (OutOfMemoryError e) { capacity = 0; } } public void push(int x) throws OverflowIntStackException { if(num>=capacity) throw new OverflowIntStackException(); arr[num++] = x; } public int pop() throws EmptyIntStackException{ if(num<=0) throw new EmptyIntStackException(); return arr[--num]; } public int result() { int result = 0; for(int i=0; i<arr.length;i++) result += arr[i]; return result; } public boolean isEmpty() { if(num <= 0) return true; else return false; } public int peek() throws EmptyIntStackException { if(num<=0) throw new EmptyIntStackException(); return arr[num-1]; } public int size() { return num; } public static void main(String[] args) throws IOException { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out)); int n = Integer.parseInt(br.readLine()); int [] student = new int[n]; StringTokenizer st = new StringTokenizer(br.readLine()); for(int i=0; i<n;i++) student[i] = Integer.parseInt(st.nextToken()); bw.write(snack(student)); bw.flush(); bw.close(); br.close(); } public static String snack(int [] x) { int num = 1; Main m = new Main(x.length); boolean result = true; for(int i=0; i<5;i++) { if(x[i] != num) { try { m.push(x[i]); }catch(Main.OverflowIntStackException e) { } } else { num++; } } for(int i=0;i<m.size();i++) { int val = m.pop(); if(val == num) num++; else { result = false; break; } } return result? "Nice" : "Sad"; } }
댓글을 작성하려면
로그인
해야 합니다.
wodnr54071 2년 전
어떤 부분이 틀렸는지 잘 모르겠습니다..