https://www.acmicpc.net/problem/1920
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;
import java.util.HashMap;
import java.util.Map;
import java.util.ArrayList;
public class Main {
static int N,M;
static ArrayList<Integer> ans = new ArrayList<>();
static Map<Integer,Boolean> nMap = new HashMap<>();
public static void main(String[] args) throws IOException{
BufferedReader br =new BufferedReader(new InputStreamReader(System.in));
StringTokenizer st =new StringTokenizer(br.readLine());
N = Integer.parseInt(st.nextToken());
st = new StringTokenizer(br.readLine());
for(int i=0;i<N;i++){
nMap.put(Integer.parseInt(st.nextToken()),true);
}
st =new StringTokenizer(br.readLine());
M = Integer.parseInt(st.nextToken());
st = new StringTokenizer(br.readLine());
for(int i=0;i<M;i++){
Integer tempKey = Integer.parseInt(st.nextToken());
// true : 존재 , false : 부재
Boolean result = nMap.getOrDefault(tempKey,false);
if (result) {
ans.add(1);
} else {
ans.add(0);
}
}
for(int i=0;i<ans.size();i++){
System.out.println(ans.get(i));
}
}
}
'코딩테스트' 카테고리의 다른 글
[알고리즘 문제풀이] 백준 17484 진우의 달 여행 (완전탐색,DFS) (1) | 2024.11.18 |
---|---|
[알고리즘 문제풀이] 백준 11479 서로 다른 부분 문자열의 개수 (문자열 응용) (1) | 2024.11.15 |
[알고리즘 문제풀이] 백준14891번 톱니바퀴 ( 구현 ) (1) | 2024.11.12 |
[알고리즘 문제 풀이] 백준 117244 연결 요소의 개수 (BFS/DFS) (0) | 2024.07.14 |
[알고리즘 문제 풀이] 백준 2667 단지번호붙이기 (BFS/DFS) (0) | 2024.07.10 |