슈콩

[BOJ] 백준 10816 숫자 카드 2 본문

Algorithms/Baekjoon

[BOJ] 백준 10816 숫자 카드 2

shukong 2025. 9. 16. 19:52

[문제]

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

 

 

[소스 코드]

import java.io.*;
import java.util.*;
public class Main {
	public static void main(String[] args) throws IOException {
		HashMap<Integer,Integer> hm = new HashMap<>();
		StringBuilder sb = new StringBuilder();
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		StringTokenizer st;
		int n = Integer.parseInt(br.readLine());
		st = new StringTokenizer(br.readLine());
		for(int i=0;i<n;i++) {
			int x = Integer.parseInt(st.nextToken());
			if(!hm.containsKey(x)) {
				hm.put(x, 1);
			}
			else {
				int val = hm.get(x);
				hm.put(x, val+1);
			}
		}
		int m = Integer.parseInt(br.readLine());
		st = new StringTokenizer(br.readLine());
		for(int i=0;i<m;i++) {
			int x = Integer.parseInt(st.nextToken());
			if(hm.containsKey(x)) {
				sb.append(hm.get(x)+" ");
			}
			else
				sb.append(0 +" ");
		}
		System.out.println(sb);
	}
}

'Algorithms > Baekjoon' 카테고리의 다른 글

[BOJ] 백준 2295 세 수의 합  (0) 2025.09.16
[BOJ] 백준 18870 좌표 압축  (0) 2025.09.16
[BOJ] 백준 1920 수 찾기  (0) 2025.09.16
[BOJ] 백준 9613 GCD 합  (0) 2025.09.16
[BOJ] 백준 9020 골드바흐의 추측  (0) 2025.09.15