백준 17219

김경욱·2025년 8월 24일

백준

목록 보기
57/121

import java.util.;
import java.io.
;

// 1 10 13 16
public class Main {
public static void main(String[] args) throws IOException {

    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

    StringTokenizer st = new StringTokenizer(br.readLine());

    int N = Integer.parseInt(st.nextToken());

    int M = Integer.parseInt(st.nextToken());

String[] M2 = new String[M];
HashMap<String,String> set = new HashMap<>();

    for (int i = 0; i < N; i++)
    {
        StringTokenizer st2 = new StringTokenizer(br.readLine());
       set.put(st2.nextToken(),st2.nextToken());
    }

    for (int i = 0; i < M; i++)
    {
        M2[i] = br.readLine();
    }

    for (int i = 0 ; i < M; i++ )
    {

        if (set.containsKey(M2[i]))
        {
            System.out.println(set.get(M2[i]));
        }

    }


















}

}

값이 두개가 주어질 때는 HashMap을 사용하고 하나만 있을 경우엔 HashSet을 사용한다. 또한 HashMap은 add가 아닌 put이고 출력할 땐 get이다. 이때 Map은 값이 두개이므로 하나의 값은 넣으면 나머지 값이 나온다.

0개의 댓글