diff --git a/1.js b/1.js new file mode 100644 index 0000000..4bf750f --- /dev/null +++ b/1.js @@ -0,0 +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 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/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