Skip to content

Commit 9a8166d

Browse files
committed
[Silver IV] Title: 듣보잡, Time: 268 ms, Memory: 26320 KB -BaekjoonHub
1 parent 702ae0b commit 9a8166d

2 files changed

Lines changed: 66 additions & 0 deletions

File tree

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
# [Silver IV] 듣보잡 - 1764
2+
3+
[문제 링크](https://www.acmicpc.net/problem/1764)
4+
5+
### 성능 요약
6+
7+
메모리: 26320 KB, 시간: 268 ms
8+
9+
### 분류
10+
11+
자료 구조, 해시를 사용한 집합과 맵, 정렬, 문자열
12+
13+
### 제출 일자
14+
15+
2025년 3월 17일 17:43:04
16+
17+
### 문제 설명
18+
19+
<p>김진영이 듣도 못한 사람의 명단과, 보도 못한 사람의 명단이 주어질 때, 듣도 보도 못한 사람의 명단을 구하는 프로그램을 작성하시오.</p>
20+
21+
### 입력
22+
23+
<p>첫째 줄에 듣도 못한 사람의 수 N, 보도 못한 사람의 수 M이 주어진다. 이어서 둘째 줄부터 N개의 줄에 걸쳐 듣도 못한 사람의 이름과, N+2째 줄부터 보도 못한 사람의 이름이 순서대로 주어진다. 이름은 띄어쓰기 없이 알파벳 소문자로만 이루어지며, 그 길이는 20 이하이다. N, M은 500,000 이하의 자연수이다.</p>
24+
25+
<p>듣도 못한 사람의 명단에는 중복되는 이름이 없으며, 보도 못한 사람의 명단도 마찬가지이다.</p>
26+
27+
### 출력
28+
29+
<p>듣보잡의 수와 그 명단을 사전순으로 출력한다.</p>
30+
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
import java.io.BufferedReader;
2+
import java.io.IOException;
3+
import java.io.InputStreamReader;
4+
import java.util.ArrayList;
5+
import java.util.Collections;
6+
import java.util.HashSet;
7+
8+
public class Main {
9+
public static void main(String[] args) throws IOException {
10+
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
11+
String[] inputs = br.readLine().split(" ");
12+
int n = Integer.parseInt(inputs[0]);
13+
int m = Integer.parseInt(inputs[1]);
14+
15+
HashSet<String> set = new HashSet<>();
16+
for (int i = 0; i < n; i++) {
17+
set.add(br.readLine());
18+
}
19+
20+
ArrayList<String> result = new ArrayList<>();
21+
for (int i = 0; i < m; i++) {
22+
String tmp = br.readLine();
23+
if(set.contains(tmp)){
24+
result.add(tmp);
25+
}
26+
}
27+
28+
Collections.sort(result);
29+
30+
// print result
31+
System.out.println(result.size());
32+
for (String s : result) {
33+
System.out.println(s);
34+
}
35+
}
36+
}

0 commit comments

Comments
 (0)