회원가입
로그인
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
글쓰기
질문 도움말
자주묻는 질문
5430번 문제 런타임 에러 도와주세요..
5430번 - AC
evan191
4년 전
0
무엇 때문에 런타임에러가 발생하는지 모르겠습니다..
#include <cstdio> #include <cstdlib> #include <iostream> using namespace std; class Queue; class Node{ friend class Queue; private: int data; Node *prev; Node *next; public: Node(int data){ this->data = data; prev = (Node*)NULL; next = (Node*)NULL; } Node(int data, Node *prev, Node *next){ this->data = data; this->prev = prev; this->next = next; } }; class Queue{ private: Node *head; Node *tail; int length; char state; public: Queue(){ head = 0; tail = 0; length = 0; state = 'N'; } void push(int data){ if(!head){ head = new Node(data); tail = head; } else{ Node *tmp = new Node(data); tail->next = tmp; tmp->prev = tail; tail = tail->next; } length++; } void push(char state){ if(this->state=='N'){ this->state = state; } else if(this->state=='R'){ this->state = 'N'; } } int pop(){ if(state=='N'){ if(empty()) throw "error"; int tmp = head->data; Node *del = head; head = head->next; delete del; length--; return tmp; } else if(state=='R'){ if(empty()) throw "error"; int tmp = tail->data; Node *del = tail; tail = tail->prev; tail->next = 0; delete del; length--; return tmp; } } bool empty(){ return length==0; } void print(){ int len = length; if(state=='N'){ Node *tmp = head; printf("%c", '['); while(len--){ printf("%d", tmp->data); if(len) printf(","); tmp = tmp->next; } printf("]\n"); } else if(state=='R'){ Node *tmp = tail; printf("["); while(len--){ printf("%d", tmp->data); if(len) printf(","); tmp = tmp->prev; } printf("]\n"); } } }; int main() { int test; scanf("%d", &test); while(test--){ char func[200001] = {0}; try{ Queue q; scanf("%s", func); int n; scanf("%d", &n); char *number = new char[5*n+10]{0}; int num[n]; int tmp = 0; int lindex = 0; scanf("%s", number); for(int i=0;number[i]!='\0';i++){ char temp[10] = {0}; tmp = 0; while('0'<=number[i] && number[i]<='9'){ temp[tmp++] = number[i]; i++; } if(tmp){ num[lindex++] = atoi(temp); } } int index = 0; for(;index<n;index++) q.push(num[index]); for(int i=0;func[i]!='\0';i++){ switch(func[i]){ case 'R': q.push(func[i]); break; case 'D': q.pop(); break; } } q.print(); delete[] number; } catch(const char *expression){ printf("%s\n", expression); } } return 0; }
댓글을 작성하려면
로그인
해야 합니다.
evan191 4년 전
무엇 때문에 런타임에러가 발생하는지 모르겠습니다..