회원가입
로그인
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
문제집
대회
채점 현황
게시판
그룹
더 보기
재채점 기록
블로그
도움말
전체
공지
자유
질문
오타/오역/요청
게시판 공지
홍보
업데이트
solved.ac
글쓰기
질문 도움말
자주묻는 질문
10퍼센트만 가고 틀리는데
4949번 - 균형잡힌 세상
0723jongmin
2년 전
0
예시대로 하면 답이 다 맞는것 같은데 흠 머가 문제일까요?
#include <stdio.h> #include <stdlib.h> #include<string.h> #include<stdbool.h> #define size 1000000 typedef struct{ int top; int result; char stack[size]; }stacktype; void init(stacktype *c){ c->top = -1; c->result = 0; } bool empty(stacktype *c){ if(c->top == -1){ return true; } return false; } bool full(stacktype *c){ if(c->top == size-1){ return true; } return false; } void insert(stacktype *c, char item){ if(full(c)){ return; } c->top++; c->stack[c->top] = item; } void pop(stacktype *c){ if(empty(c)){ return; } c->top--; } int main(void){ char button; char take[100]={0}; stacktype *str; str = malloc(sizeof(stacktype)); init(str); while(take[0] != '.'){ fgets(take, sizeof(take), stdin); for(int i =0; i<strlen(take); i++){ if (take[i] == '(' || take[i] == '[') { insert(str, take[i]); } else if (take[i] == ')') { for(int i=0; i<str->top+1; i++){ if (!empty(str) && str->stack[i] == '(') { pop(str); } } } else if (take[i] == ']') { for(int i =0; i<str->top+1; i++){ if (!empty(str) && str->stack[i] == '[') { pop(str); } } } } if (empty(str)) { printf("yes\n"); } else { printf("no\n"); } init(str); //memset(take, 0, sizeof(take)); } free(str); return 0; }
댓글을 작성하려면
로그인
해야 합니다.
0723jongmin 2년 전
예시대로 하면 답이 다 맞는것 같은데 흠 머가 문제일까요?