main
[백준-10815번/Java] 숫자 카드 본문
https://www.acmicpc.net/problem/10815
10815번: 숫자 카드
첫째 줄에 상근이가 가지고 있는 숫자 카드의 개수 N(1 ≤ N ≤ 500,000)이 주어진다. 둘째 줄에는 숫자 카드에 적혀있는 정수가 주어진다. 숫자 카드에 적혀있는 수는 -10,000,000보다 크거나 같고, 10,
www.acmicpc.net
* Map 을 사용해서 풀었다.
import java.io.*;
import java.util.*;
import java.math.*;
public class Main {
public static void main(String[] args) throws IOException {
Scanner in = new Scanner(System.in);
int N = in.nextInt();
Map<Integer, Integer> card = new HashMap<Integer, Integer>();
for (int i = 0; i < N; i++) {
card.put(in.nextInt(), 1);
}
int M = in.nextInt();
for (int i = 0; i < M; i++) {
if (card.get(in.nextInt()) != null) {
System.out.print("1 ");
} else {
System.out.print("0 ");
}
}
}
}
728x90
'Algorithm' 카테고리의 다른 글
[백준-7568번/Java] 덩치 (0) | 2022.11.21 |
---|---|
[백준-2231번/Java] 분해합 (0) | 2022.11.20 |
[백준-1966번/Java] 프린터 큐 (0) | 2022.11.19 |
[백준-1271번/Java] 엄청난 부자2 (0) | 2022.11.19 |
[Array-9/Java] 격자판 최대합 (0) | 2022.11.19 |
Comments