[백준, BOJ 10815] 숫자 카드 (java)
Problem Solving/BOJ

[백준, BOJ 10815] 숫자 카드 (java)

728x90

https://www.acmicpc.net/problem/10815

메모리: 135,456 KB , 시간: 816 ms

사용 알고리즘: 자료 구조, 해시를 사용한 집합과 맵

728x90

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.HashSet;
import java.util.Set;
import java.util.StringTokenizer;

public class Main {

    public static void main(String[] args) throws Exception{

        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        StringTokenizer st;

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

        Set<Integer> card = new HashSet<>();
        st = new StringTokenizer(br.readLine());
        for (int i = 0; i < N; i++) {
            card.add(Integer.parseInt(st.nextToken()));
        }

        StringBuilder result = new StringBuilder();

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

        st = new StringTokenizer(br.readLine());
        int c;
        for (int i = 0; i < M; i++) {
            c = Integer.parseInt(st.nextToken());

            if(card.contains(c)) result.append("1 ");
            else result.append("0 ");
        }

        System.out.println(result);
    }
}
728x90