From 6a14272c73c6bb70fbbc918b5ae9b6f12c55b405 Mon Sep 17 00:00:00 2001 From: Junseo Kim Date: Thu, 25 Jul 2024 04:33:50 +0900 Subject: [PATCH 01/13] =?UTF-8?q?2024-07-24=20=ED=95=98=EB=85=B8=EC=9D=B4?= =?UTF-8?q?=20=ED=83=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- oesnuj/README.md | 1 + "oesnuj/\354\236\254\352\267\200/1914.cpp" | 33 ++++++++++++++++++++++ 2 files changed, 34 insertions(+) create mode 100644 "oesnuj/\354\236\254\352\267\200/1914.cpp" diff --git a/oesnuj/README.md b/oesnuj/README.md index 1052526..bc15eeb 100644 --- a/oesnuj/README.md +++ b/oesnuj/README.md @@ -13,4 +13,5 @@ | 9차시 | 2024.05.30 | 구현 | [빙고](https://www.acmicpc.net/problem/2578) | [#30](https://github.com/AlgoLeadMe/AlgoLeadMe-10/pull/30) | | 10차시 | 2024.07.04 | 구현 | [상어초등학교](https://www.acmicpc.net/problem/21608) | [#34](https://github.com/AlgoLeadMe/AlgoLeadMe-10/pull/34) | | 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) | --- diff --git "a/oesnuj/\354\236\254\352\267\200/1914.cpp" "b/oesnuj/\354\236\254\352\267\200/1914.cpp" new file mode 100644 index 0000000..9074b25 --- /dev/null +++ "b/oesnuj/\354\236\254\352\267\200/1914.cpp" @@ -0,0 +1,33 @@ +#include +#include +#include +using namespace std; + +void RecurMoveDisks(int n, int from, int temp, int to) { + if (n == 0) return; + //n-1개의 원판으로 temp로 옮긴다. + RecurMoveDisks(n - 1, from, to, temp); + + //남은 1개의 원판으로 to로 옮긴다. <- 이때 옮기는 과정 출력 + cout << from + 1 << " " << to + 1 << "\n"; + + //temp에 있던 n-1개의 원판을 n-1개로 옮긴다. + RecurMoveDisks(n - 1, temp, from, to); +} + +int main() { + ios::sync_with_stdio(false); cin.tie(nullptr); + int n; + cin >> n; + + //2의 n제곱 -1 출력하기 + string cnt = to_string(pow(2, n)); + int x = cnt.find('.'); + cnt = cnt.substr(0, x); + cnt[cnt.length() - 1] -= 1; + cout << cnt << "\n"; + + //조건에 맞는 경우에만 재귀를 돌린다. + if (n <= 20) RecurMoveDisks(n, 0, 1, 2); + return 0; +} \ No newline at end of file From fc20d4239374dac116be46d5823bb5772450289f Mon Sep 17 00:00:00 2001 From: Junseo Kim Date: Thu, 25 Jul 2024 05:31:45 +0900 Subject: [PATCH 02/13] Update 1914.cpp --- "oesnuj/\354\236\254\352\267\200/1914.cpp" | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git "a/oesnuj/\354\236\254\352\267\200/1914.cpp" "b/oesnuj/\354\236\254\352\267\200/1914.cpp" index 9074b25..90b8165 100644 --- "a/oesnuj/\354\236\254\352\267\200/1914.cpp" +++ "b/oesnuj/\354\236\254\352\267\200/1914.cpp" @@ -9,7 +9,7 @@ void RecurMoveDisks(int n, int from, int temp, int to) { RecurMoveDisks(n - 1, from, to, temp); //남은 1개의 원판으로 to로 옮긴다. <- 이때 옮기는 과정 출력 - cout << from + 1 << " " << to + 1 << "\n"; + cout << from << " " << to << "\n"; //temp에 있던 n-1개의 원판을 n-1개로 옮긴다. RecurMoveDisks(n - 1, temp, from, to); @@ -28,6 +28,6 @@ int main() { cout << cnt << "\n"; //조건에 맞는 경우에만 재귀를 돌린다. - if (n <= 20) RecurMoveDisks(n, 0, 1, 2); + if (n <= 20) RecurMoveDisks(n, 1, 2, 3); return 0; } \ No newline at end of file From 2b4a619cd5bda910b4d891368b95ed6f45a71c2c Mon Sep 17 00:00:00 2001 From: Junseo Kim Date: Sun, 28 Jul 2024 03:42:50 +0900 Subject: [PATCH 03/13] =?UTF-8?q?2024-07-28=20=EB=B6=80=EB=85=80=ED=9A=8C?= =?UTF-8?q?=EC=9E=A5=EC=9D=B4=20=EB=90=A0=ED=85=8C=EC=95=BC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- oesnuj/DP/2775.cpp | 53 ++++++++++++++++++++++++++++++++++++++++++++++ oesnuj/README.md | 1 + 2 files changed, 54 insertions(+) create mode 100644 oesnuj/DP/2775.cpp diff --git a/oesnuj/DP/2775.cpp b/oesnuj/DP/2775.cpp new file mode 100644 index 0000000..c7cf2e6 --- /dev/null +++ b/oesnuj/DP/2775.cpp @@ -0,0 +1,53 @@ +/*풀이1 재귀만 이용*/ +//#include +//using namespace std; +// +//int calc(int k, int n) { +// if (k == 0) return n; +// int sum = 0; +// for (int i = n; i > 0; i--) { +// sum += calc(k - 1, i); +// } +// return sum; +//} +// +//int main() +//{ +// int T, k, n; +// cin >> T; +// while (T--) { +// cin >> k >> n; +// cout << calc(k, n) << "\n"; +// } +// return 0; +//} + +/*풀이2, 재귀 + DP*/ +#include +#include +using namespace std; + +vector> dp; + +int calc(int k, int n) { + if (k == 0) return n; + if (dp[k][n] != -1) return dp[k][n]; // 이미 계산된 값이면 반환 + + int sum = 0; + for (int i = n; i > 0; i--) { + sum += calc(k - 1, i); + } + return dp[k][n] = sum; // 계산된 값을 저장하고 반환 +} + +int main() +{ + int T, k, n; + cin >> T; + while (T--) { + cin >> k >> n; + dp = vector>(k + 1, vector(n + 1, -1)); //케이스별 DP 테이블 초기화 + cout << calc(k, n) << "\n"; + } + return 0; +} diff --git a/oesnuj/README.md b/oesnuj/README.md index bc15eeb..7d0b194 100644 --- a/oesnuj/README.md +++ b/oesnuj/README.md @@ -14,4 +14,5 @@ | 10차시 | 2024.07.04 | 구현 | [상어초등학교](https://www.acmicpc.net/problem/21608) | [#34](https://github.com/AlgoLeadMe/AlgoLeadMe-10/pull/34) | | 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) | --- From 20e59d32a5c69edae3fc99f963bb3dd63d8164af Mon Sep 17 00:00:00 2001 From: Junseo Kim Date: Tue, 6 Aug 2024 05:00:36 +0900 Subject: [PATCH 04/13] =?UTF-8?q?2024-08-05=20=EB=82=98=EB=8A=94=EC=95=BC?= =?UTF-8?q?=20=ED=8F=AC=EC=BC=93=EB=AA=AC=20=EB=A7=88=EC=8A=A4=ED=84=B0=20?= =?UTF-8?q?=EC=9D=B4=EB=8B=A4=EC=86=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- oesnuj/README.md | 1 + "oesnuj/\355\225\264\354\213\234/1620.js" | 27 +++++++++++++++++++++++ 2 files changed, 28 insertions(+) create mode 100644 "oesnuj/\355\225\264\354\213\234/1620.js" 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 From 060f3d835ca293d4ee58eed61a4754c3c6f003d9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B9=80=EC=A4=80=EC=84=9C=20Junseo=20Kim?= Date: Tue, 6 Aug 2024 23:25:13 +0900 Subject: [PATCH 05/13] Update 1620.js --- "oesnuj/\355\225\264\354\213\234/1620.js" | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git "a/oesnuj/\355\225\264\354\213\234/1620.js" "b/oesnuj/\355\225\264\354\213\234/1620.js" index d78b8f5..3511f15 100644 --- "a/oesnuj/\355\225\264\354\213\234/1620.js" +++ "b/oesnuj/\355\225\264\354\213\234/1620.js" @@ -15,13 +15,12 @@ pokemonList.forEach((pokemon, index) => { let result = ''; testList.forEach(test => { - const num = Number(test); - if (!isNaN(num)) { + if (!isNaN(test)) { // 테스트 값이 번호인 경우 - result += pokemonList[num - 1] + '\n'; // 번호에 해당하는 Pokémon 이름 추가 + result += pokemonList[test - 1] + '\n'; // 번호에 해당하는 Pokémon 이름 추가 } else { // 테스트 값이 이름인 경우 result += pokemonMap.get(test) + '\n'; // 이름에 해당하는 Pokémon 번호 추가 } }); -console.log(result); \ No newline at end of file +console.log(result); From 00e8e235c91cee7a6c3f7ecbdc919259d2a58f91 Mon Sep 17 00:00:00 2001 From: Junseo Kim Date: Thu, 5 Sep 2024 16:55:40 +0900 Subject: [PATCH 06/13] =?UTF-8?q?=EC=B6=A9=EB=8F=8C=20=EA=B3=A0=EC=B9=98?= =?UTF-8?q?=EA=B8=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- oesnuj/DP/2775.cpp | 53 ---------------------- "oesnuj/\354\236\254\352\267\200/1914.cpp" | 33 -------------- 2 files changed, 86 deletions(-) delete mode 100644 oesnuj/DP/2775.cpp delete mode 100644 "oesnuj/\354\236\254\352\267\200/1914.cpp" diff --git a/oesnuj/DP/2775.cpp b/oesnuj/DP/2775.cpp deleted file mode 100644 index c7cf2e6..0000000 --- a/oesnuj/DP/2775.cpp +++ /dev/null @@ -1,53 +0,0 @@ -/*풀이1 재귀만 이용*/ -//#include -//using namespace std; -// -//int calc(int k, int n) { -// if (k == 0) return n; -// int sum = 0; -// for (int i = n; i > 0; i--) { -// sum += calc(k - 1, i); -// } -// return sum; -//} -// -//int main() -//{ -// int T, k, n; -// cin >> T; -// while (T--) { -// cin >> k >> n; -// cout << calc(k, n) << "\n"; -// } -// return 0; -//} - -/*풀이2, 재귀 + DP*/ -#include -#include -using namespace std; - -vector> dp; - -int calc(int k, int n) { - if (k == 0) return n; - if (dp[k][n] != -1) return dp[k][n]; // 이미 계산된 값이면 반환 - - int sum = 0; - for (int i = n; i > 0; i--) { - sum += calc(k - 1, i); - } - return dp[k][n] = sum; // 계산된 값을 저장하고 반환 -} - -int main() -{ - int T, k, n; - cin >> T; - while (T--) { - cin >> k >> n; - dp = vector>(k + 1, vector(n + 1, -1)); //케이스별 DP 테이블 초기화 - cout << calc(k, n) << "\n"; - } - return 0; -} diff --git "a/oesnuj/\354\236\254\352\267\200/1914.cpp" "b/oesnuj/\354\236\254\352\267\200/1914.cpp" deleted file mode 100644 index 90b8165..0000000 --- "a/oesnuj/\354\236\254\352\267\200/1914.cpp" +++ /dev/null @@ -1,33 +0,0 @@ -#include -#include -#include -using namespace std; - -void RecurMoveDisks(int n, int from, int temp, int to) { - if (n == 0) return; - //n-1개의 원판으로 temp로 옮긴다. - RecurMoveDisks(n - 1, from, to, temp); - - //남은 1개의 원판으로 to로 옮긴다. <- 이때 옮기는 과정 출력 - cout << from << " " << to << "\n"; - - //temp에 있던 n-1개의 원판을 n-1개로 옮긴다. - RecurMoveDisks(n - 1, temp, from, to); -} - -int main() { - ios::sync_with_stdio(false); cin.tie(nullptr); - int n; - cin >> n; - - //2의 n제곱 -1 출력하기 - string cnt = to_string(pow(2, n)); - int x = cnt.find('.'); - cnt = cnt.substr(0, x); - cnt[cnt.length() - 1] -= 1; - cout << cnt << "\n"; - - //조건에 맞는 경우에만 재귀를 돌린다. - if (n <= 20) RecurMoveDisks(n, 1, 2, 3); - return 0; -} \ No newline at end of file From 699ca479011b60661e22104adc7cfd8919c1e223 Mon Sep 17 00:00:00 2001 From: Junseo Kim Date: Thu, 5 Sep 2024 16:56:30 +0900 Subject: [PATCH 07/13] Delete 1620.js --- "oesnuj/\355\225\264\354\213\234/1620.js" | 26 ----------------------- 1 file changed, 26 deletions(-) delete mode 100644 "oesnuj/\355\225\264\354\213\234/1620.js" diff --git "a/oesnuj/\355\225\264\354\213\234/1620.js" "b/oesnuj/\355\225\264\354\213\234/1620.js" deleted file mode 100644 index 3511f15..0000000 --- "a/oesnuj/\355\225\264\354\213\234/1620.js" +++ /dev/null @@ -1,26 +0,0 @@ -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 => { - if (!isNaN(test)) { - // 테스트 값이 번호인 경우 - result += pokemonList[test - 1] + '\n'; // 번호에 해당하는 Pokémon 이름 추가 - } else { - // 테스트 값이 이름인 경우 - result += pokemonMap.get(test) + '\n'; // 이름에 해당하는 Pokémon 번호 추가 - } -}); -console.log(result); From 9b6ed77e4b4d4733cc6faff5bc500b367c869eb2 Mon Sep 17 00:00:00 2001 From: Junseo Kim Date: Thu, 5 Sep 2024 16:57:51 +0900 Subject: [PATCH 08/13] Create 1620.js --- "oesnuj/\355\225\264\354\213\234/1620.js" | 26 +++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 "oesnuj/\355\225\264\354\213\234/1620.js" 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..fdb616c --- /dev/null +++ "b/oesnuj/\355\225\264\354\213\234/1620.js" @@ -0,0 +1,26 @@ +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 => { + if (!isNaN(test)) { + // 테스트 값이 번호인 경우 + result += pokemonList[test - 1] + '\n'; // 번호에 해당하는 Pokémon 이름 추가 + } else { + // 테스트 값이 이름인 경우 + result += pokemonMap.get(test) + '\n'; // 이름에 해당하는 Pokémon 번호 추가 + } +}); +console.log(result); \ No newline at end of file From 4fe92702ab8611d2533ff17d221bdd058fa50f25 Mon Sep 17 00:00:00 2001 From: Junseo Kim Date: Thu, 5 Sep 2024 17:02:12 +0900 Subject: [PATCH 09/13] Delete 1620.js --- "oesnuj/\355\225\264\354\213\234/1620.js" | 26 ----------------------- 1 file changed, 26 deletions(-) delete mode 100644 "oesnuj/\355\225\264\354\213\234/1620.js" diff --git "a/oesnuj/\355\225\264\354\213\234/1620.js" "b/oesnuj/\355\225\264\354\213\234/1620.js" deleted file mode 100644 index fdb616c..0000000 --- "a/oesnuj/\355\225\264\354\213\234/1620.js" +++ /dev/null @@ -1,26 +0,0 @@ -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 => { - if (!isNaN(test)) { - // 테스트 값이 번호인 경우 - result += pokemonList[test - 1] + '\n'; // 번호에 해당하는 Pokémon 이름 추가 - } else { - // 테스트 값이 이름인 경우 - result += pokemonMap.get(test) + '\n'; // 이름에 해당하는 Pokémon 번호 추가 - } -}); -console.log(result); \ No newline at end of file From ed33cb1031da78ae8ed77da71ead8626a5e98874 Mon Sep 17 00:00:00 2001 From: Junseo Kim Date: Thu, 5 Sep 2024 17:05:50 +0900 Subject: [PATCH 10/13] Create 1620.txt --- "oesnuj/\355\225\264\354\213\234/1620.txt" | 1 + 1 file changed, 1 insertion(+) create mode 100644 "oesnuj/\355\225\264\354\213\234/1620.txt" diff --git "a/oesnuj/\355\225\264\354\213\234/1620.txt" "b/oesnuj/\355\225\264\354\213\234/1620.txt" new file mode 100644 index 0000000..0519ecb --- /dev/null +++ "b/oesnuj/\355\225\264\354\213\234/1620.txt" @@ -0,0 +1 @@ + \ No newline at end of file From fbf3a048b1b776060f7eb235142bec21912afc27 Mon Sep 17 00:00:00 2001 From: Junseo Kim Date: Thu, 5 Sep 2024 17:09:03 +0900 Subject: [PATCH 11/13] Delete 1620.txt --- "oesnuj/\355\225\264\354\213\234/1620.txt" | 1 - 1 file changed, 1 deletion(-) delete mode 100644 "oesnuj/\355\225\264\354\213\234/1620.txt" diff --git "a/oesnuj/\355\225\264\354\213\234/1620.txt" "b/oesnuj/\355\225\264\354\213\234/1620.txt" deleted file mode 100644 index 0519ecb..0000000 --- "a/oesnuj/\355\225\264\354\213\234/1620.txt" +++ /dev/null @@ -1 +0,0 @@ - \ No newline at end of file From 01f9af9469d4ed9d9ef193b5d9276bdebc0cbf17 Mon Sep 17 00:00:00 2001 From: Junseo Kim Date: Thu, 5 Sep 2024 17:10:15 +0900 Subject: [PATCH 12/13] =?UTF-8?q?=EC=B6=A9=EB=8F=8C=20=EA=B3=A0=EC=B9=98?= =?UTF-8?q?=EA=B8=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- "oesnuj/\355\225\264\354\213\234/1620.js" | 26 +++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 "oesnuj/\355\225\264\354\213\234/1620.js" 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..fdb616c --- /dev/null +++ "b/oesnuj/\355\225\264\354\213\234/1620.js" @@ -0,0 +1,26 @@ +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 => { + if (!isNaN(test)) { + // 테스트 값이 번호인 경우 + result += pokemonList[test - 1] + '\n'; // 번호에 해당하는 Pokémon 이름 추가 + } else { + // 테스트 값이 이름인 경우 + result += pokemonMap.get(test) + '\n'; // 이름에 해당하는 Pokémon 번호 추가 + } +}); +console.log(result); \ No newline at end of file From 3fd2e87373275313149ce9de900191cd8b2b1f82 Mon Sep 17 00:00:00 2001 From: Junseo Kim Date: Thu, 5 Sep 2024 17:12:43 +0900 Subject: [PATCH 13/13] Delete 1620.js --- "oesnuj/\355\225\264\354\213\234/1620.js" | 26 ----------------------- 1 file changed, 26 deletions(-) delete mode 100644 "oesnuj/\355\225\264\354\213\234/1620.js" diff --git "a/oesnuj/\355\225\264\354\213\234/1620.js" "b/oesnuj/\355\225\264\354\213\234/1620.js" deleted file mode 100644 index fdb616c..0000000 --- "a/oesnuj/\355\225\264\354\213\234/1620.js" +++ /dev/null @@ -1,26 +0,0 @@ -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 => { - if (!isNaN(test)) { - // 테스트 값이 번호인 경우 - result += pokemonList[test - 1] + '\n'; // 번호에 해당하는 Pokémon 이름 추가 - } else { - // 테스트 값이 이름인 경우 - result += pokemonMap.get(test) + '\n'; // 이름에 해당하는 Pokémon 번호 추가 - } -}); -console.log(result); \ No newline at end of file