Skip to content

Commit 875b094

Browse files
committed
💯Solve: basic-training/day21
1 parent 244d096 commit 875b094

File tree

5 files changed

+126
-0
lines changed

5 files changed

+126
-0
lines changed
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
// https://school.programmers.co.kr/learn/courses/30/lessons/181852
2+
3+
const readline = require('readline');
4+
const rl = readline.createInterface({
5+
input: process.stdin,
6+
output: process.stdout,
7+
});
8+
9+
let numList = [];
10+
11+
rl.on('line', (line) => {
12+
numList = line.split(' ');
13+
rl.close();
14+
}).on('close', () => {
15+
const answer = solution(numList);
16+
console.log(answer);
17+
});
18+
19+
const solution = (numList) => {
20+
return numList.sort((a, b) => a - b).slice(5);
21+
};
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// https://school.programmers.co.kr/learn/courses/30/lessons/181849
2+
3+
const readline = require('readline');
4+
const rl = readline.createInterface({
5+
input: process.stdin,
6+
output: process.stdout,
7+
});
8+
9+
let numStr = [];
10+
11+
rl.on('line', (line) => {
12+
numStr = line;
13+
rl.close();
14+
}).on('close', () => {
15+
const answer = solution(numStr);
16+
console.log(answer);
17+
});
18+
19+
const solution = nStr => Number(nStr);
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
// https://school.programmers.co.kr/learn/courses/30/lessons/181850
2+
3+
const readline = require('readline');
4+
const rl = readline.createInterface({
5+
input: process.stdin,
6+
output: process.stdout,
7+
});
8+
9+
let flo = [];
10+
11+
rl.on('line', (line) => {
12+
flo = Number(line);
13+
rl.close();
14+
}).on('close', () => {
15+
const answer = solution(flo);
16+
console.log(answer);
17+
});
18+
19+
const solution = (flo) => {
20+
return Math.floor(flo);
21+
};
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
// https://school.programmers.co.kr/learn/courses/30/lessons/181851
2+
3+
const readline = require('readline');
4+
const rl = readline.createInterface({
5+
input: process.stdin,
6+
output: process.stdout,
7+
});
8+
9+
let rank = [];
10+
let attendance = [];
11+
let count = 0;
12+
13+
rl.on('line', (line) => {
14+
if (count === 0) {
15+
rank = line.split(' ').map(Number);
16+
} else {
17+
attendance = line.split(' ').map(Number).map(item => item === 1);
18+
}
19+
count++;
20+
if (count > 1) {
21+
rl.close();
22+
}
23+
}).on('close', () => {
24+
const answer = solution(rank, attendance);
25+
console.log(answer);
26+
});
27+
28+
const solution = (rank, attendance) => {
29+
const filterArray = rank
30+
.filter((item, index) => attendance[index])
31+
.sort((a, b) => a - b)
32+
.filter((item, index) => index < 3);
33+
34+
const filterStudents = rank
35+
.filter(item => filterArray.includes(item))
36+
.sort((a, b) => a - b);
37+
38+
let arr = [];
39+
for (let i = 0; i < filterStudents.length; i++) {
40+
arr.push(rank.indexOf(filterStudents[i]));
41+
}
42+
43+
return (10000 * arr[0]) + (100 * arr[1]) + arr[2];
44+
};
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
// https://school.programmers.co.kr/learn/courses/30/lessons/181849
2+
3+
const readline = require('readline');
4+
const rl = readline.createInterface({
5+
input: process.stdin,
6+
output: process.stdout,
7+
});
8+
9+
let numStr = [];
10+
11+
rl.on('line', (line) => {
12+
numStr = line;
13+
rl.close();
14+
}).on('close', () => {
15+
const answer = solution(numStr);
16+
console.log(answer);
17+
});
18+
19+
const solution = (numStr) => {
20+
return numStr.split('').reduce((acc, cur) => Number(acc) + Number(cur));
21+
};

0 commit comments

Comments
 (0)