회원가입
로그인
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
문제집
대회
채점 현황
랭킹
게시판
그룹
더 보기
재채점 기록
블로그
강의
실험실
도움말
BOJ Stack
BOJ Book
전체
공지
자유
질문
오타/오역/요청
게시판 공지
홍보
업데이트
solved.ac
글쓰기
질문 도움말
자주묻는 질문
[C#] SegFault 에러가 나는 이유가 뭘까요 ㅠㅜㅜㅠㅜㅠㅜㅠㅜㅠㅜㅠ
18258번 - 큐 2
simplex3510
1년 전
1
도저히 모르겠습니다 도와주세요 ㅜㅜㅠㅠ
using System; using System.Text; namespace baekjoon { class Practice_18258 { public static void Main() { int inputCount = int.Parse(Console.ReadLine()); Queue queue = new Queue(); StringBuilder sb = new StringBuilder(); string[] command; for (int i = 0; i < inputCount; i++) { command = Console.ReadLine().Split(' '); switch (command[0]) { case "push": queue.Enqueue(int.Parse(command[1])); break; case "pop": sb.AppendLine(queue.Dequeue().ToString()); break; case "size": sb.AppendLine(queue.Count.ToString()); break; case "empty": sb.AppendLine(queue.IsEmpty.ToString()); break; case "front": sb.AppendLine(queue.Front.ToString()); break; case "back": sb.AppendLine(queue.Back.ToString()); break; default: break; } } Console.WriteLine(sb); } } class Queue { int count; Element frontElement; Element backElement; public int Count { get { return count; } } public int IsEmpty { get { return count == 0 ? 1 : 0; } } public int Front { get { return frontElement.Value; } } public int Back { get { return backElement.Value; } } public Queue() { count = 0; } public void Enqueue(int value) { if (Count == 0) { frontElement = backElement = new Element(value, null, null); } else { backElement = new Element(value, backElement, null); backElement.preElement.postElement = backElement; } count++; } public int Dequeue() { if (Count == 0) { return -1; } else { int value = frontElement.Value; count--; frontElement = frontElement.postElement; return value; } } } class Element { int value; public int Value { get { return value; } } public Element postElement; public Element preElement; public Element(int value, Element preElement, Element postElement) { this.value = value; this.preElement = preElement; this.postElement = postElement; } } }
댓글을 작성하려면
로그인
해야 합니다.
simplex3510 1년 전 1
도저히 모르겠습니다 도와주세요 ㅜㅜㅠㅠ