🌞Algorithm/🔥Baekjoon

[Baekjoon] 13211_Passport Checking

뿌야._. 2024. 12. 13. 02:17
문제(출처: https://www.acmicpc.net/problem/13211)

< Passport Checking >

 

문제 풀이 

 

HashSet을 사용한다.

 

 my solution (Java)

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.HashSet;
import java.util.Set;

public class _13211_ { // Passport Checking

	public static void main(String[] args) throws IOException {
		BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));
        
		int n = Integer.parseInt(bf.readLine());
        
		Set<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, m : 각 여권번호 개수
set : HashSet
result : 정답

 

n을 입력받아 n개만큼 여권 번호를 입력받아 HashSet에 저장한다. m을 입력받아 m개만큼 여권 번호를 입력받아 HashSet에 있는지 확인한다.