백준 - 2776 - 암기왕

2021. 3. 30. 13:45Algorithm

www.acmicpc.net/problem/2776

 

2776번: 암기왕

연종이는 엄청난 기억력을 가지고 있다. 그래서 하루 동안 본 정수들을 모두 기억 할 수 있다. 하지만 이를 믿을 수 없는 동규는 그의 기억력을 시험해 보기로 한다. 동규는 연종을 따라 다니며,

www.acmicpc.net

 

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
30
31
32
33
import java.util.HashSet;
import java.util.Scanner;
import java.util.Set;
 
public class 암기왕 {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int T = Integer.parseInt(sc.nextLine());
 
        for(int t=0; t<T; t++) {
            sc.nextLine();
            String[] note1 = sc.nextLine().split(" ");
            sc.nextLine();
            String[] note2 = sc.nextLine().split(" ");
            Set<String> set = new HashSet<>();
            StringBuilder sb = new StringBuilder();
 
            for(int i=0; i<note1.length; i++) {
                set.add(note1[i]);
            }
 
            for(int i=0; i<note2.length; i++) {
                if(set.contains(note2[i])) {
                    sb.append("1\n");
                } else {
                    sb.append("0\n");
                }
            }
            System.out.print(sb);
        }
    }
}
 
cs

알고리즘

  • 해싱

'Algorithm' 카테고리의 다른 글

백준 - 4963 - 섬의 개수  (0) 2021.09.07
백준 - 16926 - 배열 돌리기1  (0) 2021.04.07
백준 - 10816 - 숫자 카드2  (0) 2021.03.29
프로그래머스 - 그래프 - 가장 먼 노드  (0) 2021.03.29
백준 - 13913 - 숨바꼭질4  (0) 2021.03.27