-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
28 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); |