회원가입
로그인
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
글쓰기
질문 도움말
자주묻는 질문
런타임에러가 나는데 이유 알려주시면 그 방향으로 절 하겠습니다
7432번 - 디스크 트리
flaalrla73
4년 전
0
런타임에러가 나는데 이유 알려주시면 그 방향으로 절 하겠습니다
#include <iostream> using namespace std; const int MAX_PATH = 81; const int MAX_DIR_NAME = 9; const int MAX_DIR = 501; int N; typedef struct Node{ Node *parent; char dir_name[MAX_DIR_NAME]; Node *frontsibling; Node *nextsibling; Node *child; }Node; Node node[MAX_DIR]; int cnt; Node* node_malloc() { return &node[cnt++]; } int Strcmp(char *s1, char *s2) { while (*s1 != 0 && *s1 == *s2){ s1++; s2++; } return *s1 - *s2; } void Strcpy(char *s1, char *s2) { while (*s2 != 0) { *s1 = *s2; s1++; s2++; } *s1 = 0; } void Print_node(Node *here, int n) { while (here != 0) { for (int i = 0; i < n; i++) cout << ' '; cout << here->dir_name << '\n'; Print_node(here->child, n + 1); here = here->nextsibling; } } int main() { //freopen("input.txt", "r", stdin); //setbuf(stdout, NULL); ios_base::sync_with_stdio(false); cin.tie(NULL); cin >> N; Node *root = node_malloc(); char s[MAX_PATH]; char tmp[MAX_DIR_NAME]; int namecnt; while (N--) { cin >> s; Node *cwd = root; int i = 0; while (s[i] != 0) { namecnt = 0; while (s[i] != '\\' && s[i] != 0) { tmp[namecnt++] = s[i++]; // 여기서 이름을 하나씩 받아온다 } tmp[namecnt] = 0; Node *cursor = cwd->child; int ispresent = 0; while (cursor != 0) // 지금 받은 dir이 생성이 되어 있는지 안되어 있는지 판별 { if (Strcmp(cursor->dir_name, tmp) == 0) // 이미 생성이 되어 있음 노드 추가할 필요 x { ispresent = 1; break; } cursor = cursor->nextsibling; } if (ispresent == 1) { cwd = cursor; } else // 새로 dir 생성 { Node *new_node = node_malloc(); Strcpy(new_node->dir_name, tmp); if (cwd->child == 0) { new_node->parent = cwd; cwd->child = new_node; new_node->frontsibling = 0; new_node->nextsibling = 0; } else if (Strcmp(new_node->dir_name, cwd->child->dir_name) < 0) // child를 new_node로 바꿔야해 { new_node->nextsibling = cwd->child; cwd->child->frontsibling = new_node; cwd->child = new_node; } else // 노드 중간 중간에 들어가야 하는 경우 사전순으로 하기 위해서 { Node *temp = cwd->child; Node *femp; while (temp != 0 && Strcmp(new_node->dir_name, temp->dir_name) > 0) //temp가 더 클동안만 돌아가야해 { femp = temp; temp = temp->nextsibling; } if (temp == 0) { new_node->nextsibling = temp; new_node->frontsibling = femp; femp->nextsibling = new_node; } else //노드와 노드 중간 { new_node->nextsibling = temp; new_node->frontsibling = temp->frontsibling; temp->frontsibling->nextsibling = new_node; temp->frontsibling = new_node; } } cwd = new_node; } if (s[i] == 0) { break; } else { i++; } } } Print_node(root->child, 0); return 0; }
댓글을 작성하려면
로그인
해야 합니다.
flaalrla73 4년 전
런타임에러가 나는데 이유 알려주시면 그 방향으로 절 하겠습니다