기록하는 개발자

[백준][JAVA] 1620 : 나는야 포켓몬 마스터 이다솜 본문

Algorithm

[백준][JAVA] 1620 : 나는야 포켓몬 마스터 이다솜

밍맹030 2021. 7. 11. 16:21
728x90

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

 

1620번: 나는야 포켓몬 마스터 이다솜

첫째 줄에는 도감에 수록되어 있는 포켓몬의 개수 N이랑 내가 맞춰야 하는 문제의 개수 M이 주어져. N과 M은 1보다 크거나 같고, 100,000보다 작거나 같은 자연수인데, 자연수가 뭔지는 알지? 모르면

www.acmicpc.net

import java.util.HashMap;
import java.util.Scanner;
public class Main {
    public static void main(String []args) {
        Scanner sc=new Scanner(System.in);
        int N=sc.nextInt(), M=sc.nextInt();
        HashMap<String, Integer> map = new HashMap<>();
        String []arr=new String[N];
        
        for(int i=0; i<N; i++){
            String s= sc.next();
            arr[i]=s;
            map.put(s, i+1);
        }
        for(int i=0; i<M; i++){
            if(sc.hasNextInt()) System.out.println(arr[sc.nextInt()-1]);
            else System.out.println(map.get(sc.next()));
        }
    }
}

728x90

'Algorithm' 카테고리의 다른 글

[백준][JAVA] 1874 : 스택 수열  (0) 2021.07.11
[백준][JAVA] 10828 : 스택  (0) 2021.07.11
[백준][JAVA] 10816: 숫자 카드2  (0) 2021.07.11
[백준][JAVA] 11726: 2×n 타일링  (0) 2021.07.11
[백준][JAVA] 9095: 1, 2, 3 더하기  (0) 2021.07.11