본문 바로가기
Beakjoon&프로그래머스/Java

[백준/Java] 4368번 Babelfish

by 현장 2026. 4. 11.

-Code

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

public class BOJ4368 {
    public static void main(String[] args) throws IOException {
        BufferedReader br =
                new BufferedReader(new InputStreamReader(System.in));

        Map<String, String> translation = new HashMap<>();
        // 원래 단어와 방언 맵핑
        String line;
        while (true) {
            line = br.readLine();
            if (line == null || line.isEmpty()) break;
            StringTokenizer st = new StringTokenizer(line);
            String val = st.nextToken();
            String key = st.nextToken();
            translation.put(key, val);
        }
        // 방언을 받아 결과값 출력
        while ((line = br.readLine()) != null) {
            String result = translation.get(line);
            if (result == null) {
                // 방언에 해당하는 언어가 없는 경우
                System.out.println("eh");
            } else {
                System.out.println(result);
            }
        }
    }
}