Skip to content

Commit 3304e8b

Browse files
Merge pull request #616 from eric-hjh/main
[황장현] 89차 라이브 코테 제출
2 parents e1bc9df + bfe84da commit 3304e8b

3 files changed

Lines changed: 82 additions & 0 deletions

File tree

live8/test89/문제1/황장현.js

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
const input = require('fs')
2+
.readFileSync(process.platform === 'linux' ? '/dev/stdin' : './input.txt')
3+
.toString()
4+
.trim()
5+
.split('\n')
6+
.map((el) => el.split(' ').map(Number));
7+
8+
function solution(input) {
9+
const N = input[0][0];
10+
const elemets = input
11+
.slice(1)
12+
.flat()
13+
.sort((a, b) => a - b);
14+
15+
let answer = 4;
16+
17+
for (let i = 0; i < N; i++) {
18+
let start = i;
19+
let end = N - 1;
20+
21+
while (start < end) {
22+
if (elemets[end] - elemets[start] > 4) {
23+
end--;
24+
} else {
25+
const temp = 4 - (end - start);
26+
answer = Math.min(answer, temp);
27+
break;
28+
}
29+
}
30+
}
31+
32+
return answer;
33+
}
34+
35+
console.log(solution(input));

live8/test89/문제2/황장현.js

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
const input = require('fs')
2+
.readFileSync(process.platform === 'linux' ? '/dev/stdin' : './input.txt')
3+
.toString()
4+
.trim()
5+
.split('\n')
6+
.map((el) => el.split(' ').map(Number));
7+
8+
function solution(input) {
9+
const [N, M] = input[0];
10+
const A = input[1];
11+
12+
let answer = 0;
13+
for (let i = 0; i < N; i++) {
14+
let p1 = i;
15+
let sum = 0;
16+
17+
while (p1 < N) {
18+
sum += A[p1];
19+
20+
if (sum === M) {
21+
answer++;
22+
break;
23+
}
24+
if (sum > M) {
25+
break;
26+
}
27+
p1++;
28+
}
29+
}
30+
return answer;
31+
}
32+
33+
console.log(solution(input));

live8/test89/문제3/황장현.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
function compare(a, b) {
2+
if (b.toString()[0] !== a.toString()[0])
3+
return b.toString()[0] - a.toString()[0];
4+
else {
5+
}
6+
}
7+
8+
function solution(numbers) {
9+
numbers.sort((a, b) => compare(a, b));
10+
console.log(numbers);
11+
}
12+
13+
console.log(solution([6, 10, 2, 11]));
14+
// console.log(solution([3, 30, 34, 5, 9]));

0 commit comments

Comments
 (0)