diff --git a/oesnuj/README.md b/oesnuj/README.md index 7d0b194..7449522 100644 --- a/oesnuj/README.md +++ b/oesnuj/README.md @@ -15,4 +15,5 @@ | 11차시 | 2024.07.18 | 이분 탐색 | [랜선 자르기](https://www.acmicpc.net/problem/1654) | [#38](https://github.com/AlgoLeadMe/AlgoLeadMe-10/pull/38) | | 12차시 | 2024.07.24 | 재귀 | [하노이 탑](https://www.acmicpc.net/problem/1914) | [#41](https://github.com/AlgoLeadMe/AlgoLeadMe-10/pull/41) | | 13차시 | 2024.07.28 | DP | [부녀회장이 될테야](https://www.acmicpc.net/problem/2775) | [#44](https://github.com/AlgoLeadMe/AlgoLeadMe-10/pull/44) | +| 14차시 | 2024.08.05 | 해시 | [ 나는야 포켓몬 마스터 이다솜 ](https://www.acmicpc.net/problem/1620) | [#46](https://github.com/AlgoLeadMe/AlgoLeadMe-10/pull/46) | --- diff --git "a/oesnuj/\355\225\264\354\213\234/1620.js" "b/oesnuj/\355\225\264\354\213\234/1620.js" new file mode 100644 index 0000000..d78b8f5 --- /dev/null +++ "b/oesnuj/\355\225\264\354\213\234/1620.js" @@ -0,0 +1,27 @@ +const fs = require('fs'); +const filepath = process.platform === 'linux' ? '/dev/stdin' : './input.txt'; +const input = fs.readFileSync(filepath).toString().trim().split('\n'); + +const N = +input[0].split(' ')[0]; +const pokemonList = input.slice(1, 1 + N); +const testList = input.slice(1 + N); + +// 이름을 키로 하고 번호를 값으로 하는 단일 Map 객체 생성 +const pokemonMap = new Map(); +pokemonList.forEach((pokemon, index) => { + const number = index + 1; + pokemonMap.set(pokemon, number); +}); + +let result = ''; +testList.forEach(test => { + const num = Number(test); + if (!isNaN(num)) { + // 테스트 값이 번호인 경우 + result += pokemonList[num - 1] + '\n'; // 번호에 해당하는 Pokémon 이름 추가 + } else { + // 테스트 값이 이름인 경우 + result += pokemonMap.get(test) + '\n'; // 이름에 해당하는 Pokémon 번호 추가 + } +}); +console.log(result); \ No newline at end of file