회원가입
로그인
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
글쓰기
질문 도움말
자주묻는 질문
게시판 반례 입력해도 똑바로 나오는데 어디서 틀렸는지 모르겠습니다
10799번 - 쇠막대기
songhee7508
2년 전
1
게시판 반례들 다 입력해봐도 제대로 나옵니다.
어디서 틀렸는지 모르겠습니다.
#include <stdio.h> #include <stdlib.h> #include <string.h> ///////// 스택 typedef struct node{ int data; struct node* next; }node; typedef struct stack{ struct node* top; }stack; int is_empty(stack* s){ return s->top==NULL; } void push(stack* s, int data){ node* temp = (node*)malloc(sizeof(node)); temp->data = data; if(is_empty(s)){ s->top = temp; temp->next = NULL; } else{ temp->next = s->top; s->top = temp; } } int pop(stack* s){ if(is_empty(s)) printf("ERROR\n"); else{ node* temp = s->top; int data = temp->data; s->top = temp->next; free(temp); return data; } } stack* init(){ stack* new = (stack*)malloc(sizeof(stack)); return new; } /////// 스택 끝 void add_cutter(stack* s){ for(node* temp = s->top ; temp != NULL ; temp = temp->next){ temp->data++; } } int is_cutter(char* s, int size, int start){ if(start==size){ return 0; } else{ if(s[start]=='(' && s[start+1] == ')'){ return 1; } } } int main(){ char input[100001] = {0,}; scanf("%s", input); stack* s = init(); int ans = 0; for(int i=0; i<strlen(input); i++){ if(is_cutter(input, strlen(input), i)==1){ i++; add_cutter(s); continue; } else{ if(input[i] == '('){ push(s,1); continue; } if(input[i] == ')'){ ans += pop(s); } } } printf("%d", ans); free(s); }
댓글을 작성하려면
로그인
해야 합니다.
songhee7508 2년 전 1
게시판 반례들 다 입력해봐도 제대로 나옵니다.
어디서 틀렸는지 모르겠습니다.