회원가입
로그인
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
글쓰기
질문 도움말
자주묻는 질문
10828 반례 부탁드리겠습니다.
10828번 - 스택
jy0935
3년 전
0
반례 부탁드릴게요.
#include <stdio.h> #include <string.h> #include <stdlib.h> //10828번 스택 typedef struct command { char text[100005]; int value; }; struct command com; char* temp1; char temp[100005]; int stackData[10000]; int idx = -1; int arr[10000]; typedef struct save { char command[5]; }; struct save Save[10000]; void push(int data) { idx++; stackData[idx] = data; } int pop() { if (idx == -1) { return -1; } else { idx--; return stackData[idx + 1]; } } int size() { return idx + 1; } int top() { if (idx == -1) { return -1; } return stackData[idx]; } int empty() { if (idx == -1) { return 1; } else { return 0; } } int cut(char b[1000005]) { int a = 0; int i = 0; char* temp[2] = { NULL, }; temp1 = strtok(b, " "); while (b != NULL) { temp[i] = b; i++; b = strtok(NULL, " "); } a = atoi(temp[1]); return a; } int main() { int N = 0; scanf("%d", &N); for (int i = 0; i < N; i++) { rewind(stdin); gets(com.text); if ((int)strlen(com.text) > 5) { arr[i] = cut(com.text); memset(Save[i].command, NULL, sizeof(Save[i].command)); strcpy(Save[i].command, "push"); } else { strncpy(Save[i].command, com.text, 5); } } for (int i = 0; i < N; i++) { if (i == N - 1) { if (strstr(Save[i].command, "push") != NULL) { push(arr[i]); } else if (strcmp(Save[i].command, "pop") == 0) { printf("%d", pop()); } else if (strcmp(Save[i].command, "size") == 0) { printf("%d", size()); } else if (strstr(Save[i].command, "empty") != NULL) { printf("%d", empty()); } else if (strcmp(Save[i].command, "top") == 0) { printf("%d", top()); } } else { if (strstr(Save[i].command, "push") != NULL) { push(arr[i]); } else if (strcmp(Save[i].command, "pop") == 0) { printf("%d\n", pop()); } else if (strcmp(Save[i].command, "size") == 0) { printf("%d\n", size()); } else if (strstr(Save[i].command, "empty") != NULL) { printf("%d\n", empty()); } else if (strcmp(Save[i].command, "top") == 0) { printf("%d\n", top()); } } } }
댓글을 작성하려면
로그인
해야 합니다.
jy0935 3년 전
반례 부탁드릴게요.