Skip to content

Commit 0e0faa5

Browse files
committed
[Silver IV] Title: 숫자 카드 2, Time: 1040 ms, Memory: 171464 KB -BaekjoonHub
1 parent 0fc6524 commit 0e0faa5

File tree

2 files changed

+63
-0
lines changed

2 files changed

+63
-0
lines changed
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
# [Silver IV] 숫자 카드 2 - 10816
2+
3+
[문제 링크](https://www.acmicpc.net/problem/10816)
4+
5+
### 성능 요약
6+
7+
메모리: 171464 KB, 시간: 1040 ms
8+
9+
### 분류
10+
11+
자료 구조, 정렬, 이분 탐색, 해시를 사용한 집합과 맵
12+
13+
### 제출 일자
14+
15+
2025년 7월 18일 21:49:35
16+
17+
### 문제 설명
18+
19+
<p>숫자 카드는 정수 하나가 적혀져 있는 카드이다. 상근이는 숫자 카드 N개를 가지고 있다. 정수 M개가 주어졌을 때, 이 수가 적혀있는 숫자 카드를 상근이가 몇 개 가지고 있는지 구하는 프로그램을 작성하시오.</p>
20+
21+
### 입력
22+
23+
<p>첫째 줄에 상근이가 가지고 있는 숫자 카드의 개수 N(1 ≤ N ≤ 500,000)이 주어진다. 둘째 줄에는 숫자 카드에 적혀있는 정수가 주어진다. 숫자 카드에 적혀있는 수는 -10,000,000보다 크거나 같고, 10,000,000보다 작거나 같다.</p>
24+
25+
<p>셋째 줄에는 M(1 ≤ M ≤ 500,000)이 주어진다. 넷째 줄에는 상근이가 몇 개 가지고 있는 숫자 카드인지 구해야 할 M개의 정수가 주어지며, 이 수는 공백으로 구분되어져 있다. 이 수도 -10,000,000보다 크거나 같고, 10,000,000보다 작거나 같다.</p>
26+
27+
### 출력
28+
29+
<p>첫째 줄에 입력으로 주어진 M개의 수에 대해서, 각 수가 적힌 숫자 카드를 상근이가 몇 개 가지고 있는지를 공백으로 구분해 출력한다.</p>
30+
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
import java.util.*;
2+
import java.io.*;
3+
4+
public class Main {
5+
public static void main(String[] args) throws IOException{
6+
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
7+
8+
int N = Integer.parseInt(br.readLine());
9+
10+
HashMap<Integer, Integer> map = new HashMap<>();
11+
12+
StringTokenizer st = new StringTokenizer(br.readLine(), " ");
13+
14+
for(int i=0; i<N; i++){
15+
int card = Integer.parseInt(st.nextToken());
16+
map.put(card, map.getOrDefault(card, 0)+1);
17+
}
18+
19+
int M = Integer.parseInt(br.readLine());
20+
21+
st = new StringTokenizer(br.readLine(), " ");
22+
StringBuilder sb = new StringBuilder();
23+
for(int i=0; i<M; i++){
24+
int findCard = Integer.parseInt(st.nextToken());
25+
26+
int getCardCnt = map.getOrDefault(findCard, 0);
27+
28+
sb.append(getCardCnt + " ");
29+
}
30+
31+
System.out.println(sb);
32+
}
33+
}

0 commit comments

Comments
 (0)