티스토리 뷰
import java.io.*;
public class boj_10828 {
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int N = Integer.parseInt(br.readLine());
stack s = new stack(N);
for (int i = 0; i < N; i++) {
String str = br.readLine();
switch (str) {
case "push" : s.push(Integer.parseInt(str.split(" ")[1]));
case "pop" : s.pop();
case "size" : s.size();
case "top" : s.top();
case "empty" :
int empty = s.empty();
if (empty == 1) {
System.out.println(1);
} else {
System.out.println(0);
}
}
}
}
}
class stack {
int top;
int size;
int[] arr;
public stack(int size) {
top = -1;
this.size = size;
arr = new int[this.size];
}
public int empty() {
return top == -1 ? 1 : 0;
}
public void push(int item) {
arr[++top] = item;
}
public void pop() {
if (empty() == 1) {
System.out.println(-1);
} else {
System.out.println(arr[top]);
arr[top--] = 0;
}
}
public void top() {
if (empty() == 1) {
System.out.println(-1);
} else {
System.out.println(arr[top]);
}
}
public void size() {
System.out.println(top+1);
}
}
'PS > boj' 카테고리의 다른 글
boj)9012 - 괄호 (0) | 2020.09.13 |
---|---|
boj)9093 - 단어 뒤집기 (0) | 2020.09.13 |
boj)2644 - 촌수계산 (0) | 2020.09.05 |
boj)7576 - 토마토 (0) | 2020.09.05 |
boj)2178 - 미로 탐색 (0) | 2020.09.03 |
링크
최근에 올라온 글
최근에 달린 댓글
- Total
- Today
- Yesterday
TAG
- HTTP 완벽가이드
- 백준
- js array
- JPA 연관관계 매핑
- GCP
- 김영한 JPA
- 프로그래머스
- dreamcoding
- js promise
- 프로그래머스 SQL
- 이펙티브자바 스터디
- 백기선 스터디
- 가상 면접 사례로 배우는 대규모 시스템 설계 기초
- JS 딥다이브
- 이펙티브자바 아이템60
- ㅇㄷㅇㅈ
- 패스트캠퍼스 컴퓨터공학 완주반
- http
- HTTP 완벽 가이드
- 킹수빈닷컴
- 이펙티브자바 아이템59
- java
- 김영한 http
- js api
- REST API
- 모던자바스크립트
- BOJ
- 드림코딩
- Spring Security
- 이펙티브자바
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | 6 | |
7 | 8 | 9 | 10 | 11 | 12 | 13 |
14 | 15 | 16 | 17 | 18 | 19 | 20 |
21 | 22 | 23 | 24 | 25 | 26 | 27 |
28 | 29 | 30 |
글 보관함