const input = require('fs')
.readFileSync('/dev/stdin')
.toString()
.trim()
.split('\n')
const [n, m] = input.shift().split(' ')
const map = new Map()
for(let i=0; i<n; i++){
map.set(input[i].split(' ')[0], input[i].split(' ')[1])
}
let answer = []
for(let i=n; i<input.length; i++){
answer.push(map.get(input[i]))
}
console.log(answer.join("\n"));
자바스크립트에도 Map()이 있는 줄 몰랐었다. 사용하니까 어렵진 않았음
input[i].split(' ')[0], input[i].split(' ')[1] : input[i]를 나누고 나면 두개가 나오는데 그 두개를 각각 set에 키-밸류 인자로 전달.
input에서 map으로 넘어갈 때, n줄까지는 map에 입력하고 n 다음 줄 부터는 찾는 대상으로 처리까지 하면 쉽게 풀리는 문제
'알고리즘 (with. 백준 문제풀이) > Hash Map & Set' 카테고리의 다른 글
백준 25192번 [인사성 밝은 곰곰이] (0) | 2023.09.21 |
---|