File tree Expand file tree Collapse file tree 2 files changed +64
-3
lines changed
Expand file tree Collapse file tree 2 files changed +64
-3
lines changed Original file line number Diff line number Diff line change 44
55### 성능 요약
66
7- 메모리: 2024 KB, 시간: 340 ms
7+ 메모리: 18340 KB, 시간: 156 ms
88
99### 분류
1010
11- 자료 구조, 구현 , 스택
11+ 구현, 자료 구조, 스택
1212
1313### 제출 일자
1414
15- 2024년 4월 29일 17:46:42
15+ 2025년 10월 31일 21:15:12
1616
1717### 문제 설명
1818
Original file line number Diff line number Diff line change 1+ import java .util .*;
2+ import java .io .*;
3+
4+ public class Main {
5+ static Stack <Integer > arr = new Stack <>();
6+
7+ public static void main (String [] args ) throws IOException {
8+ BufferedReader br = new BufferedReader (new InputStreamReader (System .in ));
9+ StringBuilder sb = new StringBuilder ();
10+
11+ int N = Integer .parseInt (br .readLine ());
12+
13+ while (N -- > 0 ){
14+ StringTokenizer st = new StringTokenizer (br .readLine ());
15+ String cmd = st .nextToken ();
16+
17+ switch (cmd ){
18+ case "push" :
19+ customPush (Integer .parseInt (st .nextToken ()));
20+ break ;
21+ case "pop" :
22+ sb .append (customPop ()).append ("\n " );
23+ break ;
24+ case "size" :
25+ sb .append (customSize ()).append ("\n " );
26+ break ;
27+ case "empty" :
28+ sb .append (customEmpty ()).append ("\n " );
29+ break ;
30+ case "top" :
31+ sb .append (customTop ()).append ("\n " );
32+ break ;
33+ }
34+ }
35+
36+ System .out .println (sb );
37+ }
38+
39+ static void customPush (int n ){
40+ arr .push (n );
41+ }
42+
43+ static int customPop (){
44+ if (arr .isEmpty ()) return -1 ;
45+ else return arr .pop ();
46+ }
47+
48+ static int customSize (){
49+ return arr .size ();
50+ }
51+
52+ static int customEmpty (){
53+ if (arr .isEmpty ()) return 1 ;
54+ else return 0 ;
55+ }
56+
57+ static int customTop (){
58+ if (arr .isEmpty ()) return -1 ;
59+ else return arr .peek ();
60+ }
61+ }
You can’t perform that action at this time.
0 commit comments