반응형
아이디어
hashmap을 사용하여 키값을 통해서 value를 찾아 출력할 수 있다.
package boj;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.HashMap;
import java.util.StringTokenizer;
public class boj17219_비밀번호찾기 {
private static int N;
private static int M;
public static void main(String[] args) throws Exception{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
StringTokenizer st = new StringTokenizer(br.readLine(), " ");
N = Integer.parseInt(st.nextToken());
M = Integer.parseInt(st.nextToken());
HashMap<String, String> hash= new HashMap<>();
for(int i =0;i <N; i++) {
st = new StringTokenizer(br.readLine(), " ");
String k = st.nextToken();
String v = st.nextToken();
hash.put(k,v);
}
for(int i =0;i<M; i++) {
String find = br.readLine();
if(hash.containsKey(find)) {
System.out.println(hash.get(find));
}
}
}
}
반응형
'Algorithms' 카테고리의 다른 글
[Algorithms] 백준 11726 2XN 타일링 (0) | 2021.04.04 |
---|---|
[Algorithms] 2차원 배열 순회 (0) | 2021.02.23 |
[Algorithms] 백준 7662 이중 우선순위큐 (0) | 2020.11.05 |
[Algorithms] 백준 10816 숫자카드 (0) | 2020.10.28 |
[Algorithms] 백준 14891 톱니바퀴 (0) | 2020.10.28 |