반응형
문제 |
소스 |
import java.util.HashSet;
import java.util.Scanner;
public class Main {
static int N, M, answer;
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
N = sc.nextInt();
HashSet<Integer> hs = new HashSet<Integer>();
for(int i=0; i<N; i++) {
hs.add(sc.nextInt()); // N의 정수 A(HasSet)에 담기
}
M = sc.nextInt();
int arr[] = new int[M];
for(int i=0; i<M; i++) {
arr[i] = sc.nextInt();
}
for(int i=0; i<M; i++) {
if (hs.contains(arr[i])) { // M개의 수들이 A에 존재하는지 체크
answer = 1;
} else {
answer = 0;
}
System.out.println(answer);
}
}
}
출처 |
https://www.acmicpc.net/problem/1920
반응형
'알고리즘 > JAVA' 카테고리의 다른 글
[JAVA] 백준 알고리즘 2156 : 포도주 (DP) (0) | 2018.10.11 |
---|---|
[JAVA] 백준 알고리즘 1912 : 연속합 (DP) (0) | 2018.10.10 |
[JAVA] 백준 알고리즘 2869 : 달팽이는 올라가고 싶다 (2) | 2018.09.20 |
[JAVA] 백준 알고리즘 2583 : 영역 구하기 (0) | 2018.09.19 |
[JAVA] 백준 알고리즘 10825 : 국영수 (0) | 2018.09.18 |