Skip to content

정용훈 제출합니다. #21

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions 1.js
Original file line number Diff line number Diff line change
@@ -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());
22 changes: 22 additions & 0 deletions 2.js
Original file line number Diff line number Diff line change
@@ -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());
74 changes: 74 additions & 0 deletions 3.js
Original file line number Diff line number Diff line change
@@ -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());
13 changes: 13 additions & 0 deletions 4.js
Original file line number Diff line number Diff line change
@@ -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());
34 changes: 34 additions & 0 deletions 5.js
Original file line number Diff line number Diff line change
@@ -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());
1 change: 1 addition & 0 deletions input.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
입력값을 작성하는 텍스트 파일