Skip to content

Commit

Permalink
Feat:Add solution of #118
Browse files Browse the repository at this point in the history
  • Loading branch information
sa11k committed Jul 27, 2022
1 parent 3b80c55 commit 49fd3bf
Showing 1 changed file with 36 additions and 0 deletions.
36 changes: 36 additions & 0 deletions src/BaekJoon/sa11k/10828/Main_220728.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import java.io.*;
import java.util.*;

class Main_220728 {

public static void main(String[] args) throws Exception {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
StringBuilder sb = new StringBuilder();
int N = Integer.parseInt(br.readLine());
Stack<Integer> stack = new Stack<>();

for(int i = 0; i<N; i++){
StringTokenizer st = new StringTokenizer(br.readLine(), " ");
String command = st.nextToken();
if(command.equals("push")) stack.push(Integer.parseInt(st.nextToken()));
else if(command.equals("pop")){
if (stack.isEmpty()) sb.append(-1).append("\n");
else sb.append(stack.pop()).append("\n");
}
else if (command.equals("size")) sb.append(stack.size()).append("\n");
else if (command.equals("empty")){
if (stack.isEmpty()) sb.append(1).append("\n");
else sb.append(0).append("\n");
}
else if(command.equals("top")){
if (stack.isEmpty()) sb.append(-1).append("\n");
else sb.append(stack.peek()).append("\n");
}
}

System.out.println(sb);


br.close();
}
}

0 comments on commit 49fd3bf

Please sign in to comment.