Skip to content

Commit f205445

Browse files
Merge pull request #568 from eric-hjh/main
[황장헌] 75차 라이브 코테 제출
2 parents db5984c + 2e0edde commit f205445

File tree

4 files changed

+105
-0
lines changed

4 files changed

+105
-0
lines changed

live7/test74/문제3/황장현.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
function solution(n, left, right) {
2+
const result = [];
3+
4+
for (let index = left; index <= right; index++) {
5+
const row = Math.floor(index / n);
6+
const col = index % n;
7+
result.push(Math.max(row + 1, col + 1));
8+
}
9+
10+
return result;
11+
}
12+
13+
console.log(solution(3, 2, 5));

live7/test75/문제1/황장현.js

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
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 map = input.slice(1);
11+
let count = 0;
12+
13+
function 재귀(sum, prevPlace, day) {
14+
if (day === N) {
15+
if (sum >= M) count++;
16+
return;
17+
}
18+
19+
for (let i = 0; i < 2; i++) {
20+
for (let j = 0; j < 3; j++) {
21+
let temp = sum;
22+
if (j === prevPlace) {
23+
temp += map[i][j] / 2;
24+
} else {
25+
temp += map[i][j];
26+
}
27+
재귀(temp, j, day + 1);
28+
}
29+
}
30+
}
31+
32+
for (let i = 0; i < 2; i++) {
33+
for (let j = 0; j < 3; j++) {
34+
const sum = map[i][j];
35+
재귀(sum, j, 1);
36+
}
37+
}
38+
39+
return count;
40+
}
41+
42+
console.log(solution(input));

live7/test75/문제2/황장현.js

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
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+
let 최솟값 = Infinity;
11+
const map = input.slice(1);
12+
13+
function 재귀(index, 신맛, 쓴맛, used) {
14+
if (used > 0) 최솟값 = Math.min(최솟값, Math.abs(신맛 - 쓴맛));
15+
16+
if (index === N) return;
17+
18+
재귀(index + 1, 신맛 * map[index][0], 쓴맛 + map[index][1], used + 1);
19+
재귀(index + 1, 신맛, 쓴맛, used);
20+
}
21+
22+
재귀(0, 1, 0, 0);
23+
console.log(최솟값);
24+
}
25+
26+
console.log(solution(input));

live7/test75/문제3/황장현.js

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
function solution(s) {
2+
const temp = s
3+
.slice(2, -2)
4+
.split('},{')
5+
.map((s) => s.split(',').map(Number));
6+
7+
temp.sort((a, b) => a.length - b.length);
8+
9+
const result = [];
10+
const seen = new Set();
11+
12+
for (const arr of temp) {
13+
for (const num of arr) {
14+
if (!seen.has(num)) {
15+
result.push(num);
16+
seen.add(num);
17+
}
18+
}
19+
}
20+
21+
return result;
22+
}
23+
24+
console.log(solution('{{2},{2,1},{2,1,3},{2,1,3,4}}'));

0 commit comments

Comments
 (0)