회원가입
로그인
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
글쓰기
질문 도움말
자주묻는 질문
왜 틀렸을까요
9012번 - 괄호
zzsin123
7년 전
0
왜 틀렸을까요
스택 구현해서 한건데 반례를 못찾겠네요
#include <stdio.h> #include <malloc.h> #include <string.h> struct node{ int name; struct node * next; struct node * prev; }; struct nodelist{ struct node *cur; struct node *head; struct node *tail; }; struct nodelist *nlist; bool underflow; int size = 0; void initnode(){ nlist = (struct nodelist*)malloc(sizeof(struct nodelist)); nlist->head = NULL; nlist->tail = NULL; nlist->cur = NULL; size = 0; underflow = false; } void push_back(int num){ struct node * newnode = (struct node*)malloc(sizeof(struct node)); newnode->name = num; if (nlist->head != NULL) nlist->head->prev = newnode; newnode->next = nlist->head; newnode->prev = NULL; if (nlist->head == NULL && nlist->tail == NULL){ nlist->head = newnode; nlist->tail = newnode; } else{ nlist->head = newnode; } size++; } bool empty(){ if (size == 0) return 1; else return 0; } void pop_back(){ if (empty()) underflow = true; else{ nlist->cur = nlist->head; if (nlist->head->next == NULL){ nlist->tail = NULL; nlist->head = NULL; } else{ nlist->head = nlist->head->next; nlist->head->prev = NULL; nlist->cur->prev = NULL; nlist->cur->next = NULL; } nlist->cur->name = NULL; free(nlist->cur); size--; } } int front(){ if (empty()) return -1; else return nlist->tail->name; } int back(){ if (empty()) return -1; else return nlist->head->name; } int main(void){ initnode(); int num = 0; scanf("%d", &num); char **insert = (char **)malloc(sizeof(char)*num); int insertnum = 0; char **outsert = (char **)malloc(sizeof(char)*num); for (int i = 0; i < num; i++){ initnode(); insert[i] = (char *)malloc(sizeof(char)*50); outsert[i] = "NO\n"; scanf("%s", insert[i]); if(insert[i][0] == ')') outsert[i] = "NO\n"; else{ for (int j = 0; insert[i][j] != '\0'; j++){ if (insert[i][j] == '(') push_back(j); else pop_back(); } if (empty() && underflow == false) outsert[i] = "YES\n"; } printf("%s",outsert[i]); } return 0; }
댓글을 작성하려면
로그인
해야 합니다.
zzsin123 7년 전
왜 틀렸을까요
스택 구현해서 한건데 반례를 못찾겠네요