🌞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에 저장한다. 이메일 개수를 입력받아 이메일 개수만큼 이메일을 입력받는다. 이메일이 연락처에 있는 이메일인지 확인한다.



 

'🌞Algorithm > 🔥Baekjoon' 카테고리의 다른 글

[Baekjoon] 9357_Eligibility  (1) 2025.01.22
[Baekjoon] 6973_Dynamic Dictionary Coding  (0) 2025.01.21
[Baekjoon] 9951_Word Extraction  (1) 2025.01.17
[Baekjoon] 11518_Morse  (0) 2025.01.16
[Baekjoon] 4775_Spelling Be  (1) 2025.01.15