백준 1920번(Java)

박은지·2025년 2월 5일
0

백준

목록 보기
24/89
post-thumbnail

import java.io.*;
import java.util.*;

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());
		
		int[] nums = Arrays.stream(br.readLine().split(" "))
                			.mapToInt(Integer::parseInt)
                			.toArray();
		Arrays.sort(nums);
		int M = Integer.parseInt(br.readLine());
		int[] check = Arrays.stream(br.readLine().split(" "))
							.mapToInt(Integer::parseInt)
							.toArray();
		int[] result = new int[M];
		
		for(int i=0; i<M; i++) {
			int num = check[i];
			int mid = (nums.length / 2);
			
			if(num >= nums[mid]) {
				for(int j=mid; j<nums.length; j++) {
					if(nums[j] == num) {
						result[i] = 1;
						break;
					}
				}
			} else {
				for(int j=mid-1; j>=0; j--) {
					if(nums[j] == num) {
						result[i] = 1;
						break;
					}
				}
			}
		}
	
		for(int re:result) {
			System.out.println(re);
		}
	}
}
profile
백엔드 개발자가 되고싶은 eunzi😊

0개의 댓글