We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
package main.java.com.poogle.BOJ.Q10828; import java.io.*; import java.util.Stack; public class Main { public static void main(String[] args) throws IOException { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); int n = Integer.parseInt(br.readLine()); Stack<String> stack = new Stack<>(); while (n-- > 0) { String[] command = br.readLine().split(" "); switch (command[0]) { case "push": stack.push(command[1]); break; case "pop": if (!stack.isEmpty()) { System.out.println(stack.pop()); } else { System.out.println("-1"); } break; case "size": System.out.println(stack.size()); break; case "empty": if (stack.isEmpty()) { System.out.println("1"); } else { System.out.println("0"); } break; case "top": if (!stack.isEmpty()) { System.out.println(stack.peek()); } else { System.out.println("-1"); } break; default: break; } } br.close(); } }
package main.java.com.poogle.BOJ.Q10828; import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.StringTokenizer; public class Main { public static int[] stack; public static int size = 0; public static void main(String[] args) throws IOException { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); StringBuilder sb = new StringBuilder(); StringTokenizer st; int N = Integer.parseInt(br.readLine()); stack = new int[N]; while (N-- > 0) { st = new StringTokenizer(br.readLine(), " "); switch (st.nextToken()) { case "push": push(Integer.parseInt(st.nextToken())); break; case "pop": sb.append(pop()).append('\n'); break; case "size": sb.append(size()).append('\n'); break; case "empty": sb.append(empty()).append('\n'); break; case "top": sb.append(top()).append('\n'); break; } } System.out.println(sb); } public static void push(int item) { stack[size] = item; size++; } public static int pop() { if (size == 0) { return -1; } else { int res = stack[size - 1]; stack[size - 1] = 0; size--; return res; } } public static int size() { return size; } public static int empty() { if (size == 0) { return 1; } else { return 0; } } public static int top() { if (size == 0) { return -1; } else { return stack[size - 1]; } } }
The text was updated successfully, but these errors were encountered:
boj: 10828 풀이
3562690
스택으로 풀이 Issue #20
b95c62e
suhyunsim
No branches or pull requests
문제
핵심 아이디어
어려운 점, 실수
풀이
The text was updated successfully, but these errors were encountered: