Skip to content

Commit

Permalink
백설공주 완료
Browse files Browse the repository at this point in the history
  • Loading branch information
alli-eunbi committed Apr 28, 2022
1 parent fc45ac7 commit d9d53f9
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 48 deletions.
16 changes: 8 additions & 8 deletions item_scout_interview/ex.txt
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
7
8
6
5
1
37
30
28
22
36
10
13
15
19
20
23
25
77 changes: 37 additions & 40 deletions item_scout_interview/snow_white.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,34 +44,34 @@
// 22

//* 내 답안
function solution(arr) {
const rest =
arr.reduce((a, b) => {
return a + b;
}, 0) - 100;

let answer = [];
outerFor: for (let x = 0; x < arr.length; x++) {
for (let y = arr.length - 1; y > 0; y--) {
if (arr[x] + arr[y] === rest) {
answer.push(x);
answer.push(y);
break outerFor;
}
}
x++;
}
// function solution(arr) {
// const rest =
// arr.reduce((a, b) => {
// return a + b;
// }, 0) - 100;

answer.sort();
arr.splice(answer[0], 1);
arr.splice(answer[1] - 1, 1);
return arr;
}
// let answer = [];
// outerFor: for (let x = 0; x < arr.length; x++) {
// for (let y = 1; y < arr.length; y++) {
// if (arr[x] + arr[y] === rest) {
// answer.push(x);
// answer.push(y);
// break outerFor;
// }
// }
// x++;
// }

// answer.sort();
// arr.splice(answer[0], 1);
// arr.splice(answer[1] - 1, 1);
// return arr;
// }

const arr = [20, 7, 23, 19, 10, 15, 25, 8, 13];
console.log(solution(arr));
const arr1 = [8, 6, 5, 1, 37, 30, 28, 22, 36];
console.log(solution(arr1));
// const arr = [20, 7, 23, 19, 10, 15, 25, 8, 13];
// console.log(solution(arr));
// const arr1 = [8, 6, 5, 1, 37, 30, 28, 22, 36];
// console.log(solution(arr1));
//* 다른 사람 답안

//★ 배운점
Expand Down Expand Up @@ -107,32 +107,29 @@ console.log(solution(arr1));
// console.log(solution(arr));

let fs = require("fs");
let arr = require("fs").readFileSync("ex.txt").toString().split("\n");
let arr = require("fs")
.readFileSync("ex.txt")
.toString()
.split("\n")
.map(Number);
// let arr = fs.readFileSync("/dev/stdin").toString().split("\n");

console.log(arr);
const rest =
arr.reduce((a, b) => {
return Number(a) + Number(b);
return a + b;
}, 0) - 100;

console.log(rest);
let answer = [];
outerFor: for (let x = 0; x < arr.length; x++) {
for (let y = arr.length - 1; y > 0; y--) {
if (Number(arr[x]) + Number(arr[y]) === rest) {
answer.push(Number(x));
answer.push(Number(y));
outerFor: for (let x = 0; x < arr.length - 1; x++) {
innerFor: for (let y = 1; y < arr.length; y++) {
if (arr[x] + arr[y] === rest) {
arr.splice(y, 1);
arr.splice(x, 1);
break outerFor;
}
}
x++;
}

answer.sort();
arr.splice(answer[0], 1);
arr.splice(answer[1] - 1, 1);
console.log(arr);
arr.map((a) => {
console.log(a);
});

0 comments on commit d9d53f9

Please sign in to comment.