반응형
전체 탐색으로 하면 시간 초과가 날 것 같아서 HashSet를 사용했다.
또한, 중복된 수가 없었기 때문에 HashSet 사용이 가능했다.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 | import java.io.FileInputStream; import java.util.HashSet; import java.util.Scanner; public class Main { public static void main(String[] args) throws Exception { // TODO Auto-generated method stub Scanner sc = new Scanner(new FileInputStream("input.txt")); // Scanner sc = new Scanner(System.in); int N = sc.nextInt(); HashSet<Integer> set = new HashSet<Integer>(); for (int i = 0; i < N; i++) { set.add(sc.nextInt()); } int M = sc.nextInt(); for (int i = 0; i < M; i++) { if (set.contains(sc.nextInt())) { System.out.print(1); } else { System.out.print(0); } System.out.print(" "); } } } | cs |
반응형
'나는요 공부가 좋....은걸... > 알고리즈음' 카테고리의 다른 글
[BOJ] 백준 5598 - 카이사르 (자바) (0) | 2018.01.22 |
---|---|
[BOJ] 백준 2839 - 설탕배달 (자바) (0) | 2018.01.22 |
[BOJ] 백준 2751 - 수 정렬하기 2 (자바) (0) | 2018.01.19 |
[BOJ] 백준 2947 - 나무 조각 (자바) (0) | 2018.01.19 |
[BOJ] 백준 2193 - 이친수 (자바) (0) | 2018.01.18 |