🐣 알고리즘 삐약/💻 백준 삐약

101 삐약 : 백준 1620 | 나는야 포켓몬 마스터 이다솜 [바킹독| HASH |JAVA]

우주수첩 2024. 10. 31. 16:22
728x90

https://www.acmicpc.net/problem/1620

 

package BKD_0x15_Hash;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.HashMap;
import java.util.StringTokenizer;

public class BOJ_1620 {
    public static void main(String[] args) throws IOException {
        HashMap<String,Integer> strKey = new HashMap<>();
        HashMap<Integer,String> intKey = new HashMap<>();

        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());

        for(int i=1;i<=N;i++){
            String input = br.readLine();
            strKey.put(input,i);
            intKey.put(i,input);
        }


        for(int i=0;i<M;i++){
            String question = br.readLine();
            if(question.charAt(0)>=49 && question.charAt(0)<=57){
                System.out.println(intKey.get(Integer.parseInt(question)));
            }else{
                System.out.println(strKey.get(question));
            }
        }
    }
}

 

  • 아스키코드와 두 개의 HashMap으로 해결.
  • 순자인 문자열의 아스키코드가 얼마인지 몰라따 ㅇㅅㅇ.
    • '0'=48 / '9'=57임.

728x90