Skip to content

Commit cb59057

Browse files
committed
[Silver IV] Title: 문자열 집합, Time: 2924 ms, Memory: 32484 KB -BaekjoonHub
1 parent 4623e05 commit cb59057

File tree

2 files changed

+56
-0
lines changed

2 files changed

+56
-0
lines changed
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
# [Silver IV] 문자열 집합 - 14425
2+
3+
[문제 링크](https://www.acmicpc.net/problem/14425)
4+
5+
### 성능 요약
6+
7+
메모리: 32484 KB, 시간: 2924 ms
8+
9+
### 분류
10+
11+
자료 구조, 해시를 사용한 집합과 맵, 문자열, 트리를 사용한 집합과 맵
12+
13+
### 제출 일자
14+
15+
2024년 3월 28일 20:30:35
16+
17+
### 문제 설명
18+
19+
<p>총 N개의 문자열로 이루어진 집합 S가 주어진다.</p>
20+
21+
<p>입력으로 주어지는 M개의 문자열 중에서 집합 S에 포함되어 있는 것이 총 몇 개인지 구하는 프로그램을 작성하시오.</p>
22+
23+
### 입력
24+
25+
<p>첫째 줄에 문자열의 개수 N과 M (1 ≤ N ≤ 10,000, 1 ≤ M ≤ 10,000)이 주어진다. </p>
26+
27+
<p>다음 N개의 줄에는 집합 S에 포함되어 있는 문자열들이 주어진다.</p>
28+
29+
<p>다음 M개의 줄에는 검사해야 하는 문자열들이 주어진다.</p>
30+
31+
<p>입력으로 주어지는 문자열은 알파벳 소문자로만 이루어져 있으며, 길이는 500을 넘지 않는다. 집합 S에 같은 문자열이 여러 번 주어지는 경우는 없다.</p>
32+
33+
### 출력
34+
35+
<p>첫째 줄에 M개의 문자열 중에 총 몇 개가 집합 S에 포함되어 있는지 출력한다.</p>
36+
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import java.io.*;
2+
import java.util.*;
3+
public class Main {
4+
public static void main(String[] args) throws IOException {
5+
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
6+
int pick = Integer.parseInt(br.readLine().split(" ")[0]);
7+
String[] arrStr = br.lines().limit(pick).toArray(String[] :: new);
8+
String[] arrStr2 = br.lines().takeWhile(l -> !l.isEmpty()).toArray(String[] :: new);
9+
int[] c = {0};
10+
for(String str : arrStr) {
11+
Arrays.stream(arrStr2)
12+
.forEach(r -> {
13+
if(r.equals(str)) {
14+
++c[0];
15+
}
16+
});
17+
}
18+
System.out.println(c[0]);
19+
}
20+
}

0 commit comments

Comments
 (0)