Notice
Recent Posts
Recent Comments
Link
«   2024/10   »
1 2 3 4 5
6 7 8 9 10 11 12
13 14 15 16 17 18 19
20 21 22 23 24 25 26
27 28 29 30 31
Tags
more
Archives
Today
Total
관리 메뉴

main

[백준-10815번/Java] 숫자 카드 본문

Algorithm

[백준-10815번/Java] 숫자 카드

1984 2022. 11. 20. 19:56

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 ");
			}
		}

	}

}

'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