From 54a8fefc6b0a96b1fa352692d4ca5b34e6a28a06 Mon Sep 17 00:00:00 2001 From: Yonghoon Date: Sat, 20 Nov 2021 19:58:40 +0900 Subject: [PATCH 1/3] =?UTF-8?q?=EC=A0=95=EC=9A=A9=ED=9B=88=20=EC=BD=94?= =?UTF-8?q?=EB=94=A9=ED=85=8C=EC=8A=A4=ED=8A=B8=20=EC=A0=9C=EC=B6=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- codingTest.js | 18 ++++++++++++++++++ codingTest2.js | 11 +++++++++++ codingTest3.js | 28 ++++++++++++++++++++++++++++ codingTest4.js | 34 ++++++++++++++++++++++++++++++++++ codingTest5.js | 40 ++++++++++++++++++++++++++++++++++++++++ 5 files changed, 131 insertions(+) create mode 100644 codingTest.js create mode 100644 codingTest2.js create mode 100644 codingTest3.js create mode 100644 codingTest4.js create mode 100644 codingTest5.js diff --git a/codingTest.js b/codingTest.js new file mode 100644 index 0000000..fbed5be --- /dev/null +++ b/codingTest.js @@ -0,0 +1,18 @@ +const fs = require("fs"); +const filePath = process.platform === "linux" ? "/dev/stdin" : "./input.txt"; +let input = fs.readFileSync(filePath).toString().split("\n"); + +function solution() { + // 풀이 + const scores = input[0].split(", "); + + const total = scores.reduce((acc, el) => { + acc += Number(el); + return acc; + }, 0); + + const avg = Math.round(total / scores.length); + console.log(avg); +} + +console.log(solution()); diff --git a/codingTest2.js b/codingTest2.js new file mode 100644 index 0000000..1823198 --- /dev/null +++ b/codingTest2.js @@ -0,0 +1,11 @@ +const fs = require("fs"); +const filePath = process.platform === "linux" ? "/dev/stdin" : "./input.txt"; +let input = fs.readFileSync(filePath).toString().split("\n"); + +function solution() { + // 풀이 + const time = input[0].split(":"); + return [`${time[0]}시`, `${time[1]}분`, `${time[2]}초`]; +} + +console.log(solution()); diff --git a/codingTest3.js b/codingTest3.js new file mode 100644 index 0000000..0cfa496 --- /dev/null +++ b/codingTest3.js @@ -0,0 +1,28 @@ +const readline = require("readline"); + +const rl = readline.createInterface({ + input: process.stdin, + output: process.stdout, +}); + +const people = {}; + +let [typingCount, maxTypingCount] = [0, 0]; +let isNumber = true; + +rl.on("line", (input) => { + if (isNumber) { + maxTypingCount = Number(input); + isNumber = false; + return; + } + typingCount += 1; + + person = input.split(" "); + people[person[0]] = person[1]; + + if (maxTypingCount === typingCount) rl.close(); +}); +rl.on("close", () => { + console.log(people); +}); diff --git a/codingTest4.js b/codingTest4.js new file mode 100644 index 0000000..1b18667 --- /dev/null +++ b/codingTest4.js @@ -0,0 +1,34 @@ +const fs = require("fs"); +const { kill } = require("process"); +const filePath = process.platform === "linux" ? "/dev/stdin" : "./input.txt"; +let input = fs.readFileSync(filePath).toString().split("\n"); + +function solution() { + // 풀이 + const wrongWords = input[0].split(" "); + const rightWords = []; + + for (let word of wrongWords) { + for (z = 1; z <= word.length / 2; z++) { + if (word.slice(0, z) === word.slice(word.length - z)) { + word = word.substring(0, z); + rightWords.push(convertToUpAndLower(word)); + } + } + } + return rightWords.join(" "); +} + +function convertToUpAndLower(word) { + let s = ""; + for (let w of word) { + s += isUpper(w) ? w.toLowerCase() : w.toUpperCase(); + } + return s; +} + +function isUpper(w) { + return w === w.toUpperCase(); +} + +console.log(solution()); diff --git a/codingTest5.js b/codingTest5.js new file mode 100644 index 0000000..474ef99 --- /dev/null +++ b/codingTest5.js @@ -0,0 +1,40 @@ +const fs = require("fs"); +const { kill } = require("process"); +const filePath = process.platform === "linux" ? "/dev/stdin" : "./input.txt"; +let input = fs.readFileSync(filePath).toString().split("\n"); + +function solution() { + // 풀이 + const modelNum = input[0].split(" "); + const brand = { + 삼성: [], + 애플: [], + hansung: [], + renover: [], + lg: [], + asus: [], + other: [], + }; + + modelNum.sort((a, b) => a - b); + for (let n of modelNum) { + if (1000 <= n && n < 2000) { + brand.삼성.push(Number(n)); + } else if (2000 <= n && n < 3000) { + brand.애플.push(Number(n)); + } else if (3000 <= n && n < 4000) { + brand.hansung.push(Number(n)); + } else if (4000 <= n && n < 5000) { + brand.renover.push(Number(n)); + } else if (5000 <= n && n < 6000) { + brand.lg.push(Number(n)); + } else if (6000 <= n && n < 7000) { + brand.asus.push(Number(n)); + } else { + brand.other.push(Number(n)); + } + } + return brand; +} + +console.log(solution()); From 4b9299debd4a41f1eedc9c4ed6ff7d24bc161b8f Mon Sep 17 00:00:00 2001 From: Yonghoon-Jung <78959175+Yonghoon-Jung@users.noreply.github.com> Date: Sat, 20 Nov 2021 20:31:10 +0900 Subject: [PATCH 2/3] Update codingTest.js Co-authored-by: woorimIT <56839474+woorim960@users.noreply.github.com> --- codingTest.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/codingTest.js b/codingTest.js index fbed5be..8458bf1 100644 --- a/codingTest.js +++ b/codingTest.js @@ -6,7 +6,7 @@ function solution() { // 풀이 const scores = input[0].split(", "); - const total = scores.reduce((acc, el) => { + const sum = scores.reduce((acc, el) => { acc += Number(el); return acc; }, 0); From ffdb71eea0913570f2bde5eaa9f426d51ad17169 Mon Sep 17 00:00:00 2001 From: Yonghoon Date: Wed, 1 Dec 2021 15:47:29 +0900 Subject: [PATCH 3/3] =?UTF-8?q?=EC=A0=95=EC=9A=A9=ED=9B=88=20=EC=BD=94?= =?UTF-8?q?=EB=94=A9=ED=85=8C=EC=8A=A4=ED=8A=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- codingTest2.js => 1.js | 11 +++++-- 2.js | 22 +++++++++++++ 3.js | 74 ++++++++++++++++++++++++++++++++++++++++++ 4.js | 13 ++++++++ 5.js | 34 +++++++++++++++++++ codingTest.js | 18 ---------- codingTest3.js | 28 ---------------- codingTest4.js | 34 ------------------- codingTest5.js | 40 ----------------------- input.txt | 1 + 10 files changed, 152 insertions(+), 123 deletions(-) rename codingTest2.js => 1.js (53%) create mode 100644 2.js create mode 100644 3.js create mode 100644 4.js create mode 100644 5.js delete mode 100644 codingTest.js delete mode 100644 codingTest3.js delete mode 100644 codingTest4.js delete mode 100644 codingTest5.js create mode 100644 input.txt diff --git a/codingTest2.js b/1.js similarity index 53% rename from codingTest2.js rename to 1.js index 1823198..4bf750f 100644 --- a/codingTest2.js +++ b/1.js @@ -1,11 +1,16 @@ const fs = require("fs"); +const { kill } = require("process"); const filePath = process.platform === "linux" ? "/dev/stdin" : "./input.txt"; let input = fs.readFileSync(filePath).toString().split("\n"); function solution() { - // 풀이 - const time = input[0].split(":"); - return [`${time[0]}시`, `${time[1]}분`, `${time[2]}초`]; + const info = input[0].split(" "); + const str = []; + for (let i = 0; i < Number(info[0]); i++) { + str[i] = info[1]; + } + + return str.join(""); } console.log(solution()); diff --git a/2.js b/2.js new file mode 100644 index 0000000..7337497 --- /dev/null +++ b/2.js @@ -0,0 +1,22 @@ +const fs = require("fs"); +const { kill } = require("process"); +const filePath = process.platform === "linux" ? "/dev/stdin" : "./input.txt"; +let input = fs.readFileSync(filePath).toString().split("\n"); + +function solution() { + const info = input[0].split(" "); + const result = []; + const minValue = Math.min.apply(null, info); + const sumValue = info.reduce((acc, el) => { + acc += Number(el); + return acc; + }, 0); + const maxValue = Math.max.apply(null, info); + + result.push(minValue); + result.push(sumValue); + result.push(maxValue); + return result; +} + +console.log(solution()); diff --git a/3.js b/3.js new file mode 100644 index 0000000..cdcd2fa --- /dev/null +++ b/3.js @@ -0,0 +1,74 @@ +const fs = require("fs"); +const { kill, prependOnceListener } = require("process"); +const filePath = process.platform === "linux" ? "/dev/stdin" : "./input.txt"; +let input = fs.readFileSync(filePath).toString().split("\n"); + +function solution() { + // fs 방식으로 객체를 입력해본적이 없어 테스트를 위해 이렇게 작성했습니다. + const person = [ + { + name: "조상우", + gender: "남자", + age: 47, + height: 181, + weight: 85, + }, + { + name: "오일남", + gender: "남자", + age: 77, + height: 175, + weight: 65, + }, + { + name: "한미녀", + gender: "여자", + age: 45, + height: 167, + weight: 49, + }, + { + name: "압둘 알리", + gender: "남자", + age: 33, + height: 172, + weight: 78, + }, + { + name: "장덕수", + gender: "남자", + age: 44, + height: 180, + weight: 73, + }, + { + name: "강새벽", + gender: "여자", + age: 27, + height: 176, + weight: 54, + }, + ]; + const people = []; + /* + for (let i = 0; i < person.length; i++) { + if ( + person[i].gender === "남자" && + 18 < person[i].age && + person[i].age < 60 && + person[i].weight >= 70 && + person[i] >= 170 + ) { + people.push(person[i].name); + } + } + + 각 객체 안의 값들을 주어진 조건에 맞도록 비교하는 반복을 + 수행한 후 조건에 일치하는 객체의 name을 people에 저장합니다. + 이후 조건에 해당되는 이름이 저장된 people을 리턴해서 출력합니다. + */ + + return people; +} + +console.log(solution()); diff --git a/4.js b/4.js new file mode 100644 index 0000000..5334e04 --- /dev/null +++ b/4.js @@ -0,0 +1,13 @@ +const fs = require("fs"); +const { kill } = require("process"); +const filePath = process.platform === "linux" ? "/dev/stdin" : "./input.txt"; +let input = fs.readFileSync(filePath).toString().split("\n"); +function solution() { + /* + 두개의 문자열을 split을 이용해 분리된 단어를 각각 배열에 저장합니다. + 만들어진 두 개의 배열의 값을 비교하며, 일치할 경우 자릿수를 누적합합니다. + 모든 비교가 끝나면 계산된 누적합을 출력합니다. + */ +} + +console.log(solution()); diff --git a/5.js b/5.js new file mode 100644 index 0000000..ff06593 --- /dev/null +++ b/5.js @@ -0,0 +1,34 @@ +const fs = require("fs"); +const { kill } = require("process"); +const filePath = process.platform === "linux" ? "/dev/stdin" : "./input.txt"; +let input = fs.readFileSync(filePath).toString().split("\n"); + +function solution() { + const pattern = input[0].split(""); + const str = input[1].split(" "); + const sumStr = []; + let count = 0; + for (let i = 0; i < pattern.length; i++) { + sumStr.push(pattern[i] + str[i]); + } + + for (let i = 1; i <= pattern.length / 2; i++) { + if (pattern[i - 1] === pattern[i]) { + if (sumStr[i - 1] !== sumStr[i]) return false; + } + + if (sumStr[i - 1] === sumStr[sumStr.length - i]) count += 1; + } + return sumStr.length === count; + + /* + 주어진 패턴을 한 글자씩 배열에 저장합니다 + 다음 문자열을 공백 기준으로 각각 배열에 저장합니다 + 이후 첫번째 패턴과 첫번째 문자열을 합쳐 하나의 문자열을 만드는 작업을 반복합니다. + 만들어진 첫번째 문자열과 마지막 문자열을 비교하여 일치하는지 확인하며 + 패턴의 길이의 반만큼 반복 비교합니다. + 아무 이상이 없을 경우 true를 반환하며 서로 대응하는 값이 다를 경우 false를 반환합니다. + */ +} + +console.log(solution()); diff --git a/codingTest.js b/codingTest.js deleted file mode 100644 index 8458bf1..0000000 --- a/codingTest.js +++ /dev/null @@ -1,18 +0,0 @@ -const fs = require("fs"); -const filePath = process.platform === "linux" ? "/dev/stdin" : "./input.txt"; -let input = fs.readFileSync(filePath).toString().split("\n"); - -function solution() { - // 풀이 - const scores = input[0].split(", "); - - const sum = scores.reduce((acc, el) => { - acc += Number(el); - return acc; - }, 0); - - const avg = Math.round(total / scores.length); - console.log(avg); -} - -console.log(solution()); diff --git a/codingTest3.js b/codingTest3.js deleted file mode 100644 index 0cfa496..0000000 --- a/codingTest3.js +++ /dev/null @@ -1,28 +0,0 @@ -const readline = require("readline"); - -const rl = readline.createInterface({ - input: process.stdin, - output: process.stdout, -}); - -const people = {}; - -let [typingCount, maxTypingCount] = [0, 0]; -let isNumber = true; - -rl.on("line", (input) => { - if (isNumber) { - maxTypingCount = Number(input); - isNumber = false; - return; - } - typingCount += 1; - - person = input.split(" "); - people[person[0]] = person[1]; - - if (maxTypingCount === typingCount) rl.close(); -}); -rl.on("close", () => { - console.log(people); -}); diff --git a/codingTest4.js b/codingTest4.js deleted file mode 100644 index 1b18667..0000000 --- a/codingTest4.js +++ /dev/null @@ -1,34 +0,0 @@ -const fs = require("fs"); -const { kill } = require("process"); -const filePath = process.platform === "linux" ? "/dev/stdin" : "./input.txt"; -let input = fs.readFileSync(filePath).toString().split("\n"); - -function solution() { - // 풀이 - const wrongWords = input[0].split(" "); - const rightWords = []; - - for (let word of wrongWords) { - for (z = 1; z <= word.length / 2; z++) { - if (word.slice(0, z) === word.slice(word.length - z)) { - word = word.substring(0, z); - rightWords.push(convertToUpAndLower(word)); - } - } - } - return rightWords.join(" "); -} - -function convertToUpAndLower(word) { - let s = ""; - for (let w of word) { - s += isUpper(w) ? w.toLowerCase() : w.toUpperCase(); - } - return s; -} - -function isUpper(w) { - return w === w.toUpperCase(); -} - -console.log(solution()); diff --git a/codingTest5.js b/codingTest5.js deleted file mode 100644 index 474ef99..0000000 --- a/codingTest5.js +++ /dev/null @@ -1,40 +0,0 @@ -const fs = require("fs"); -const { kill } = require("process"); -const filePath = process.platform === "linux" ? "/dev/stdin" : "./input.txt"; -let input = fs.readFileSync(filePath).toString().split("\n"); - -function solution() { - // 풀이 - const modelNum = input[0].split(" "); - const brand = { - 삼성: [], - 애플: [], - hansung: [], - renover: [], - lg: [], - asus: [], - other: [], - }; - - modelNum.sort((a, b) => a - b); - for (let n of modelNum) { - if (1000 <= n && n < 2000) { - brand.삼성.push(Number(n)); - } else if (2000 <= n && n < 3000) { - brand.애플.push(Number(n)); - } else if (3000 <= n && n < 4000) { - brand.hansung.push(Number(n)); - } else if (4000 <= n && n < 5000) { - brand.renover.push(Number(n)); - } else if (5000 <= n && n < 6000) { - brand.lg.push(Number(n)); - } else if (6000 <= n && n < 7000) { - brand.asus.push(Number(n)); - } else { - brand.other.push(Number(n)); - } - } - return brand; -} - -console.log(solution()); diff --git a/input.txt b/input.txt new file mode 100644 index 0000000..ec44ede --- /dev/null +++ b/input.txt @@ -0,0 +1 @@ +입력값을 작성하는 텍스트 파일 \ No newline at end of file