diff --git a/README.md b/README.md index 2277265..2868fff 100644 --- a/README.md +++ b/README.md @@ -9,11 +9,13 @@ - 어떤 문제를 풀어서 올릴지는 매 주 토요일 만나는 시간에 정한다. - 매 주 수요일 ~ 금요일 동안 서로 코드에 대한 리뷰를 남긴다. - 코드를 돌려보고, 반례, 예외찾기를 우선으로 해본다. +- 매 주 토요일 만나, 실전 문제를 해결한다. + - 실전 문제를 해결하고, 스터디원들에게 설명하기 위해 의사코드를 간략히 작성해 설명한다. ## 🙋🏻‍♂️ Participants -|이윤성|이시현|김종민|노희승| -|---|---|---|---| +|이윤성|이시현|김종민|노희승|박영규| +|---|---|---|---|---| ## 🚀 Topics and Goals diff --git a/Sort/yunseong/input/p2.txt b/Sort/yunseong/input/p2.txt new file mode 100644 index 0000000..94a339b --- /dev/null +++ b/Sort/yunseong/input/p2.txt @@ -0,0 +1,4 @@ +3 +15 +27 +12 \ No newline at end of file diff --git a/Sort/yunseong/input/p3.txt b/Sort/yunseong/input/p3.txt new file mode 100644 index 0000000..64585b7 --- /dev/null +++ b/Sort/yunseong/input/p3.txt @@ -0,0 +1,3 @@ +2 +홍길동 95 +이순신 77 diff --git a/Sort/yunseong/input/p4.txt b/Sort/yunseong/input/p4.txt new file mode 100644 index 0000000..3069aea --- /dev/null +++ b/Sort/yunseong/input/p4.txt @@ -0,0 +1,3 @@ +5 3 +1 2 5 4 3 +5 5 6 6 5 diff --git a/Sort/yunseong/problem02.js b/Sort/yunseong/problem02.js new file mode 100644 index 0000000..ee5ffe7 --- /dev/null +++ b/Sort/yunseong/problem02.js @@ -0,0 +1,12 @@ +// 입력 로직 선언 +const fs = require('fs'); +const input = fs.readFileSync('./input/p2.txt').toString().trim(); +const [n, ...inputNumbers] = input.split('\n').map((e) => +e); + +// 필요한 함수 선언 + +inputNumbers.sort((a, b) => b - a); // 내림차순 정렬 API + +const result = inputNumbers.join(' '); // 결과 배열을 공백으로 구분된 값을 나타내는 문자열로 나타냄. ex) 12 15 27 등등 + +console.log(result); diff --git a/Sort/yunseong/problem03.js b/Sort/yunseong/problem03.js new file mode 100644 index 0000000..420e833 --- /dev/null +++ b/Sort/yunseong/problem03.js @@ -0,0 +1,26 @@ +// 입력받는 로직 +const fs = require('fs'); +const input = fs.readFileSync('./input/p3.txt').toString().trim(); +const [i_n, ...i_arr] = input.split('\n'); +const n = +i_n; + +let students = []; + +class Student { + constructor(name, grade) { + this.name = name; + this.grade = grade; + } +} + +// 입력 받은 학생들 객체를 만들어 주는 로직 +i_arr.forEach((element) => { + const [name, grade] = element.split(' '); + students.push(new Student(name, +grade)); +}); + +students.sort((a, b) => a.grade - b.grade); + +const result = students.map((student) => student.name).join(' '); + +console.log(result); diff --git a/Sort/yunseong/problem04.js b/Sort/yunseong/problem04.js new file mode 100644 index 0000000..a935564 --- /dev/null +++ b/Sort/yunseong/problem04.js @@ -0,0 +1,26 @@ +// 입력받는 로직 +const fs = require('fs'); +const input = fs.readFileSync('./input/p4.txt').toString().trim(); +const inputs = input.split('\n'); +const [n, k] = inputs[0].split(' ').map((e) => +e); + +let arrA = inputs[1].split(' ').map((e) => +e); +let arrB = inputs[2].split(' ').map((e) => +e); + +// 정렬 기준을 나타내는 콜백 (sort에 전달) +const ascending = (a, b) => a - b; +const descending = (a, b) => b - a; + +arrA.sort(ascending); +arrB.sort(descending); + +let count = 0; +let max = 0; + +for (let i = 0; i < k; i++) { + if (arrA[i] < arrB[i]) { + [arrB[i], arrA[i]] = [arrA[i], arrB[i]]; + } else break; +} + +console.log(arrA.reduce((arr, cur) => arr + cur));