이번에는 백준에서 유형별로 풀어보자 해서 백준을 풀어보았다.
코드는 완성을 했으나 무엇이 문제인지 계속해서 런타임 에러가 발생했다.
백준은 어디가 문제인지, 따로 규격도 정해지지 않아서 더욱 어려웠다.
public class Main {
public static void main(String[] args) throws Exception {
new Main().solution();
exit(0);
}
public void solution() throws Exception {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
StringBuilder sb = new StringBuilder();
int N = Integer.parseInt(br.readLine());
if (N > 100000 || N < 1) {
throw new RuntimeException();
}
int[] A = new int[N];
for (int i = 0; i < N; i++) {
A[i] = Integer.parseInt(br.readLine());
}
int M = Integer.parseInt(br.readLine());
if (M > 100000 || M < 1) {
throw new RuntimeException();
}
int[] B = new int[M];
for (int i = 0; i < M; i++) {
B[i] = Integer.parseInt(br.readLine());
}
int[] answer = new int[M];
for (int i = 0; i < M; i++) {
boolean match = false;
int b = B[i];
for (int j = 0; j < N; j++) {
int a = A[j];
if (a == b) {
match = true;
break;
}
}
if (match) {
answer[i] = 1;
} else {
answer[i] = 0;
}
}
String data = Arrays.toString(answer);
sb.append(data);
System.out.println(sb);
}
}
exit(0), StringBuilder도 써보았으나 문제 해결은 되지 않았다.