🌞Algorithm/🔥Baekjoon
[Baekjoon] 29934_Important Messages
뿌야._.
2025. 1. 20. 15:18
문제(출처: https://www.acmicpc.net/problem/29934)
< Important Messages >
문제 풀이
HashSet에 이메일을 저장한 후 입력받은 이메일 중 HashSet에 저장된 이메일이 몇 개인지 구한다.
my solution (Java)
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.HashSet;
import java.io.IOException;
public class _29934_ { // Important Messages
public static void main(String[] args) throws IOException {
BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));
int n = Integer.parseInt(bf.readLine());
HashSet<String> set = new HashSet<>();
for (int i = 0; i < n; i++) {
set.add(bf.readLine());
}
int m = Integer.parseInt(bf.readLine());
int result = 0;
for (int i = 0; i < m; i++) {
if (set.contains(bf.readLine())) {
result += 1;
}
}
System.out.println(result);
}
}
변수)
n : 연락처 개수
set : 이메일 저장하는 HashSet
m : 이메일 개수
result : 연락처에 있는 이메일 개수
연락처 개수를 입력받는다. 연락처 개수만큼 이메일을 입력받아 HashSet에 저장한다. 이메일 개수를 입력받아 이메일 개수만큼 이메일을 입력받는다. 이메일이 연락처에 있는 이메일인지 확인한다.
