본문 바로가기
Beakjoon&프로그래머스/Java

[백준/Java] 10815번 숫자 카드

by 현장 2025. 12. 24.

-Code

import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;

public class BOJ10815 {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        int n = sc.nextInt();
        Map<Integer, Boolean> numMap = new HashMap<>();
        // map에 값이 주어지면 ture를 value로 저장
        for (int i = 0; i < n; i++) {
            int num = sc.nextInt();
            numMap.put(num, true);
        }

        int m = sc.nextInt();
        for (int i = 0; i < m; i++) {
            int findNum = sc.nextInt();
            // 값이 있으면 true 없으면 false
            boolean isFind = numMap.getOrDefault(findNum, false);
            System.out.print((isFind ? 1 : 0) + " ");
        }

        sc.close();
    }
}