일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 | 31 |
Tags
- analyzer test
- ELASTIC
- Kafka
- docker
- 차트
- License
- query
- aggregation
- MySQL
- Test
- TensorFlow
- 900gle
- Python
- matplotlib
- licence delete curl
- sort
- aggs
- zip 암호화
- zip 파일 암호화
- high level client
- API
- springboot
- Mac
- plugin
- token filter test
- Elasticsearch
- 파이썬
- Java
- license delete
- flask
Archives
- Today
- Total
개발잡부
[groom] Stack 본문
반응형
package kr.co.doo.cote.groom;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Stack;
import java.util.StringTokenizer;
public class Stackk {
public static void main(String[] args) throws Exception {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
StringTokenizer st = new StringTokenizer(br.readLine());
int end = Integer.parseInt(st.nextToken());
int sSize = Integer.parseInt(st.nextToken());
Stack<String> stack = new Stack<>();
for (int i = 0; i < end; i++) {
StringTokenizer stringTokenizer = new StringTokenizer(br.readLine());
String cmd = stringTokenizer.nextToken();
String num = "";
if (stringTokenizer.hasMoreTokens()) {
num = stringTokenizer.nextToken();
}
if (stack.size() == 0 && cmd.equals("pop")) {
System.out.println("Underflow");
} else if (cmd.equals("pop")) {
System.out.println(stack.pop());
}
if (stack.size() >= sSize && cmd.equals("push")) {
System.out.println("Overflow");
} else if (cmd.equals("push")) {
stack.push(num);
}
}
}
}
반응형
'이직 > groom' 카테고리의 다른 글
[groom] M배 배열 (0) | 2023.05.15 |
---|---|
[groom] Queue (0) | 2023.05.15 |
[groom] 8진수 계산기 (0) | 2023.05.15 |
[groom] 수열 - 피보나치의 수 (0) | 2023.05.13 |
[groom] 거스름돈 (0) | 2023.05.10 |
Comments