회원가입
로그인
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
문제집
대회
1
채점 현황
랭킹
게시판
그룹
더 보기
재채점 기록
블로그
강의
실험실
도움말
BOJ Stack
BOJ Book
전체
공지
자유
질문
오타/오역/요청
게시판 공지
홍보
업데이트
solved.ac
글쓰기
질문 도움말
자주묻는 질문
C언어) 게시판 모든 반례 FAQ를 봤지만 모르겠습니다..
1874번 - 스택 수열
rlaxorwn12
5년 전
0
모르겠습니다.. 살려주세요
#include <stdio.h> #include <stdlib.h> #include <stdbool.h> typedef struct Node { int data; struct Node *link; } Node; Node* createNode(int data) { Node *newNode = (Node *)malloc(sizeof(Node)); newNode->data = data; newNode->link = NULL; return newNode; } void push(Node **top, int data) { Node *newNode = createNode(data); if (*top == NULL) *top = newNode; else { newNode->link = *top; *top = newNode; } } void pop(Node **top) { Node *p; p = *top; *top = (*top)->link; free(p); } bool stackTest(int *arr, int *countNum) { for (int x = 0; x < *countNum - 2; x++) for (int y = x + 1; y < *countNum; y++) { for (int z = y + 1; z < *countNum; z++) { if (arr[x] >= arr[y] + 2 && arr[z] > arr[y]) return false; else break; } break; } return true; } void stack(Node **top, int *countNum, int *arr) { int count = 0; int i = 0; while (count != *countNum) { while (*top == NULL || (*top)->data != arr[count]) { i++; push(top, i); printf("+\n"); } pop(top); printf("-\n"); count++; } } int main(void) { Node *top = NULL; int countNum = 0; int *arr = NULL; bool check = false; scanf("%d", &countNum); arr = (int*)malloc(sizeof(int) * countNum); for (int j = 0; j < countNum; j++) scanf("%d", &arr[j]); check = stackTest(arr, &countNum); if (!check) printf("NO\n"); else stack(&top, &countNum, arr); free(arr); return 0; }
djm03178
5년 전
2
4
2
3
1
4
댓글을 작성하려면
로그인
해야 합니다.
rlaxorwn12 5년 전
모르겠습니다.. 살려주세요