Keep Going

빠르지 않아도 꾸준히

백준/Silver

[실버 4] [Java] 백준 17219번: 비밀번호 찾기

금동진 2025. 8. 28. 10:04

아이디어

간단한 HashMap 문제로 이해하고 풀었다.

이건 쿼리가 사이트 주소로만 주어져서 map.get(Query)를 하면 된다.

 

이를 코드로 구현하면 다음과 같다.

import java.io.*;
import java.util.HashMap;

public class N17219 {
    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
        String[] input = br.readLine().split(" ");
        int N = Integer.parseInt(input[0]);
        int M = Integer.parseInt(input[1]);

        HashMap<String, String> IDnPW = new HashMap<>();
        for (int i = 1; i <= N; i++) {
            input = br.readLine().split(" ");
            IDnPW.put(input[0], input[1]);
        }

        for (int i = 1; i <= M; i++) {
            input = br.readLine().split(" ");
            bw.write(IDnPW.get(input[0]) + "\n");
        }
        bw.flush();
    }
}

 


아직 초보라 많이 서툴고 틀린 부분이 있을 수 있습니다. 고수분들께서 조언해주실만한 사항이 있으면 감사히 받겠습니다.