전공공부
[BOJ_1620] 나는야 포켓몬 마스터 이다솜 본문
설명
사실상 구현 문제다.
코드
package Data_Structure;
import java.io.*;
import java.util.*;
public class BOJ_1620 {
public static void main(String[] args) throws Exception{
Scanner sc = new Scanner(System.in);
int N = sc.nextInt();
int M = sc.nextInt();
Map<String,Integer> map = new LinkedHashMap<>();
Map<Integer,String> numMap = new LinkedHashMap<>();
for(int i = 0; i < N; i++){
String str = sc.next();
map.put(str,i+1);
numMap.put(i+1,str);
}
for(int i = 0; i < M; i++){
String str = sc.next();
if(isInteger(str)){
System.out.println(numMap.get(Integer.parseInt(str)));
}else{
System.out.println(map.get(str));
}
}
}
public static boolean isInteger(String strValue) {
try {
Integer.parseInt(strValue);
return true;
} catch (NumberFormatException ex) {
return false;
}
}
}
1620번: 나는야 포켓몬 마스터 이다솜
첫째 줄에는 도감에 수록되어 있는 포켓몬의 개수 N이랑 내가 맞춰야 하는 문제의 개수 M이 주어져. N과 M은 1보다 크거나 같고, 100,000보다 작거나 같은 자연수인데, 자연수가 뭔지는 알지? 모르면
www.acmicpc.net
'Study > Problem Solving' 카테고리의 다른 글
[BOJ_1874] 스택 수열 (1) | 2023.10.28 |
---|---|
[BOJ_14425] 문자열 집합 (1) | 2023.10.26 |
[BOJ_1966] 프린터 큐 (1) | 2023.10.24 |
[BOJ_2346] 풍선 터트리기 (1) | 2023.10.23 |
[BOJ_1935] 후위표기식2 (1) | 2023.10.22 |