CodingTest
[CodingTest] 백준 1920번
동그리담
2024. 4. 17. 17:41
중복된 수만 찾으면 되기때문에 자료구조 중 중복값을 저장안하는 set을 사용해서 contains의 반복횟수를 줄였다.
import java.io.*;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.Scanner;
public class Main {
static HashSet<Integer> set = new HashSet<>();
static BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
public static void main(String[] args) throws IOException {
Scanner sc = new Scanner(System.in);
int repeat_count = sc.nextInt();
for (int i = 0; i < repeat_count; i++) {
set.add(sc.nextInt());
}
repeat_count = sc.nextInt();
for (int i = 0; i < repeat_count; i++) {
setBw(sc.nextInt());
}
bw.flush();
}
static void setBw(int x) throws IOException {
if(set.contains(x)){
bw.write("1\n");
}else {
bw.write("0\n");
}
}
}