Skip to content

Commit 2495de9

Browse files
Merge pull request #663 from eric-hjh/main
[황장현] 99차 라이브 코테 제출
2 parents 46ecf1d + d443cd1 commit 2495de9

3 files changed

Lines changed: 142 additions & 0 deletions

File tree

live9/test99/문제1/황장현.js

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
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 An = input[1];
11+
const 연산자수 = input[2];
12+
13+
let maxResult = -Infinity;
14+
let minResult = Infinity;
15+
16+
function dfs(currentIndex, total, plus, minus, multiply, divide) {
17+
if (currentIndex === An.length) {
18+
maxResult = Math.max(maxResult, total);
19+
minResult = Math.min(minResult, total);
20+
return;
21+
}
22+
23+
const currentNum = An[currentIndex];
24+
25+
if (plus > 0) {
26+
dfs(
27+
currentIndex + 1,
28+
total + currentNum,
29+
plus - 1,
30+
minus,
31+
multiply,
32+
divide
33+
);
34+
}
35+
36+
if (minus > 0) {
37+
dfs(
38+
currentIndex + 1,
39+
total - currentNum,
40+
plus,
41+
minus - 1,
42+
multiply,
43+
divide
44+
);
45+
}
46+
47+
if (multiply > 0) {
48+
dfs(
49+
currentIndex + 1,
50+
total * currentNum,
51+
plus,
52+
minus,
53+
multiply - 1,
54+
divide
55+
);
56+
}
57+
58+
if (divide > 0) {
59+
const result =
60+
total < 0
61+
? -Math.floor(Math.abs(total) / currentNum)
62+
: Math.floor(total / currentNum);
63+
64+
dfs(currentIndex + 1, result, plus, minus, multiply, divide - 1);
65+
}
66+
}
67+
68+
dfs(1, An[0], ...연산자수);
69+
const result = [];
70+
result.push(maxResult);
71+
result.push(minResult);
72+
73+
return result.join('\n');
74+
}
75+
76+
console.log(solution(input));

live9/test99/문제2/황장현.js

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
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 number = input[1].sort((a, b) => a - b);
11+
12+
const visited = Array(N).fill(false);
13+
const path = [];
14+
const result = [];
15+
16+
function dfs(depth) {
17+
if (depth === M) {
18+
result.push(path.join(' '));
19+
return;
20+
}
21+
22+
for (let i = 0; i < N; i++) {
23+
if (!visited[i]) {
24+
visited[i] = true;
25+
path.push(number[i]);
26+
dfs(depth + 1);
27+
path.pop();
28+
visited[i] = false;
29+
}
30+
}
31+
}
32+
33+
dfs(0);
34+
35+
return result.join('\n');
36+
}
37+
38+
console.log(solution(input));

live9/test99/문제3/황장현.js

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
function solution(s) {
2+
const obj = {
3+
'}': '{',
4+
']': '[',
5+
')': '(',
6+
};
7+
8+
const isCorrect = (string) => {
9+
const stack = [];
10+
for (const char of string) {
11+
if ('{[('.includes(char)) stack.push(char);
12+
else if (obj[char] !== stack.pop()) return false;
13+
}
14+
return stack.length ? false : true;
15+
};
16+
17+
const rotate = (string) => string.substringing(1) + string[0];
18+
19+
let result = 0;
20+
for (let i = 0; i < s.length; i++) {
21+
s = rotate(s);
22+
23+
result += isCorrect(s) ? 1 : 0;
24+
}
25+
return result;
26+
}
27+
28+
console.log(solution('[](){}'));

0 commit comments

Comments
 (0)