Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
71 changes: 71 additions & 0 deletions weekly/week01/BOJ_10828_스택/sukangpunch.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
package stduy.week01;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

// 스택
public class BOJ_10828 {
static class MyStack{
int [] st;
int top;

public MyStack(int size){
this.st = new int[size];
this.top = -1;
}

public void push(int x){
st[++top] = x;
}

public int pop(){
if(top == -1){
return -1;
}

return st[top--];
}

public int size(){
return top + 1;
}

public int empty(){
if(top == -1){
return 1;
}

return 0;
}

public int top(){
if(top == -1){
return -1;
}

return st[top];
}
}

public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
StringBuilder sb = new StringBuilder();

int N = Integer.parseInt(br.readLine());

MyStack stack = new MyStack(N);
for (int i = 0; i < N; i++) {
String []s = br.readLine().split(" ");

switch(s[0]){
case "push": stack.push(Integer.parseInt(s[1])); break;
case "pop": sb.append(stack.pop()).append("\n"); break;
case "size": sb.append(stack.size()).append("\n"); break;
case "empty": sb.append(stack.empty()).append("\n"); break;
case "top": sb.append(stack.top()).append("\n"); break;
}
}
System.out.println(sb);
}
}
53 changes: 53 additions & 0 deletions weekly/week01/BOJ_1920_수 찾기/sukangpunch.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
package stduy.week01;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;

public class BOJ_1920 {

static int [] A;

public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
StringBuilder sb = new StringBuilder();

int N = Integer.parseInt(br.readLine());
String [] s = br.readLine().split(" ");
A = new int[N];
for(int i=0;i<N;i++){
A[i] = Integer.parseInt(s[i]);
}
Arrays.sort(A);

int M = Integer.parseInt(br.readLine());
s = br.readLine().split(" ");

for(int i=0;i<M;i++){
int num = Integer.parseInt(s[i]);
int result = findNumByBinarySearch(0, N - 1, num);
sb.append(result).append("\n");
}

System.out.println(sb);

}

private static int findNumByBinarySearch(int start, int end, int target) {
if(start > end){
return 0;
}

int mid = (start + end) / 2;

if(A[mid] == target){
return 1;
}else if(A[mid] > target){
return findNumByBinarySearch(start, mid - 1, target);
}else{
return findNumByBinarySearch(mid + 1, end, target);
}
}

}