회원가입
로그인
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
문제집
대회
2
채점 현황
랭킹
게시판
그룹
더 보기
재채점 기록
블로그
강의
실험실
도움말
BOJ Stack
BOJ Book
전체
공지
자유
질문
오타/오역/요청
게시판 공지
홍보
업데이트
solved.ac
글쓰기
질문 도움말
자주묻는 질문
스택 자바 이클립스에선 제대로 돌아가는데 런타임 에러 이유를 모르겟어요
10828번 - 스택
cafemug
6년 전
0
채점중 뜨다가 런타임 에러 뜨네요 이유가 무엇인가요?ㅠㅠ
import java.io.*; public class Main { private int count =0; private Node top; private class Node{ private int data; private Node nextNode; Node (int data){ this.data = data; } } void push(int data){ Node new_node = new Node(data); if (count ==0){ top = new_node; }else{ new_node.nextNode = top; top = new_node; } count++; } int top(){ if (top == null){ return -1; }else { int x=top.data; return x; } } int pop(){ if (top == null){ return -1; } else { Node tmp = top; top = tmp.nextNode; int t=tmp.data; tmp = null; count--; return t; } } int size(){ return count; } int empty(){ if (top==null){ return 1; }else { return 0; } } public static void main(String[] args) throws IOException{ Main a = new Main(); InputStreamReader isr =new InputStreamReader(System.in); BufferedReader in = new BufferedReader(isr); String str; String temp; String[] tlist; str = in.readLine(); int number = Integer.parseInt(str); while (number>0){ temp =in.readLine(); if (temp.charAt(1)=='u'){ tlist=temp.split(" "); int ik =Integer.parseInt(tlist[1]); a.push(ik); } else{ if(temp.equals("pop")){ System.out.println(a.pop()); } else if(temp.equals("empty")){ System.out.println(a.empty()); } else if(temp.equals("size")){ System.out.println(a.size()); } else if(temp.equals("top")){ System.out.println(a.top()); } } } } }
댓글을 작성하려면
로그인
해야 합니다.
cafemug 6년 전
채점중 뜨다가 런타임 에러 뜨네요 이유가 무엇인가요?ㅠㅠ