Skip to content

Commit

Permalink
2024-08-05 나는야 포켓몬 마스터 이다솜
Browse files Browse the repository at this point in the history
  • Loading branch information
oesnuj committed Aug 5, 2024
1 parent 2b4a619 commit 20e59d3
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
1 change: 1 addition & 0 deletions oesnuj/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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) |
---
27 changes: 27 additions & 0 deletions oesnuj/해시/1620.js
Original file line number Diff line number Diff line change
@@ -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);

0 comments on commit 20e59d3

Please sign in to comment.