공부/백준
[백준-10815] 숫자 카드 - Java
빈v
2022. 5. 31. 21:27
728x90
https://www.acmicpc.net/problem/10815
10815번: 숫자 카드
첫째 줄에 상근이가 가지고 있는 숫자 카드의 개수 N(1 ≤ N ≤ 500,000)이 주어진다. 둘째 줄에는 숫자 카드에 적혀있는 정수가 주어진다. 숫자 카드에 적혀있는 수는 -10,000,000보다 크거나 같고, 10,
www.acmicpc.net
HashSet을 사용하여 풀었다.
HashSet에 가지고 있는 카드를 추가하여 중복확인을 하였다.
코드
import java.util.*;
public class back10815 {
public static void main(String args[]){
Scanner scanner = new Scanner(System.in);
int num=scanner.nextInt();
HashSet<Integer> set = new HashSet<>();
for(int i=0;i<num;i++){
int temp=scanner.nextInt();
set.add(temp);
}
num=scanner.nextInt();
int []arr=new int[num];
for(int i=0;i<num;i++){
int temp=scanner.nextInt();
if(set.contains(temp)){
arr[i]=1;
}
}
for(int i=0;i<num;i++){
System.out.print(arr[i]+" ");
}
}
}
728x90
반응형