코딩테스트/백준문제

[Java] 백준_1920_수찾기

jaewon_sss 2021. 5. 21. 00:37
반응형

https://www.acmicpc.net/problem/1920

 

 

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class Main {
	static BufferedReader input = new BufferedReader(new InputStreamReader(System.in));
	static StringTokenizer tokens;
	static int N, num, flag;
	static int[] A;
	static int M;
	static StringBuilder output = new StringBuilder();
	public static void main(String[] args) throws NumberFormatException, IOException {
		N = Integer.parseInt(input.readLine());
		A = new int[N];
		tokens = new StringTokenizer(input.readLine());
		for (int n = 0; n < N; n++) {
			A[n] = Integer.parseInt(tokens.nextToken());
		}
		M = Integer.parseInt(input.readLine());
		tokens = new StringTokenizer(input.readLine());
		for (int m = 0; m < M; m++) {
			flag= 0;
			num = Integer.parseInt(tokens.nextToken());
			
			for (int n = 0; n < N; n++) {
				if(A[n] == num) {
					flag = 1;
					break;
				}
			}
			output.append(flag + "\n");
		}
		System.out.println(output);
	}
}
반응형

'코딩테스트 > 백준문제' 카테고리의 다른 글

[Java] 백준_10815_숫자카드  (0) 2021.05.24
[Java] 백준_2750_수 정렬하기  (0) 2021.05.22
[Java] 백준_14501_퇴사  (0) 2021.05.20
[Java] 백준_13458_시험감독  (0) 2021.05.19
[Java] 백준_14696_딱지놀이  (0) 2021.02.25