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
'🐣 알고리즘 삐약 > 💻 백준 삐약' 카테고리의 다른 글
103 삐약 : 백준 17219 | 비밀번호 찾기 [바킹독| HASH |JAVA] (0) | 2024.10.31 |
---|---|
102 삐약 : 백준 13414 | 수강신청 [바킹독| HASH |JAVA] (0) | 2024.10.31 |
100 삐약 : 백준 7785 | 회사에 있는 사람 [바킹독| HASH |JAVA] (0) | 2024.10.31 |
99 삐약 : 백준 1182 | 부분 수열의 합 [바킹독| 백트래킹 |JAVA] (0) | 2024.09.15 |
98 삐약 : 백준 9663 | N-Queen [바킹독| 백트래킹 |JAVA] (0) | 2024.09.15 |