Skip to content

Commit 86f0fea

Browse files
Merge pull request #658 from jinoo0306/main
[조진우] 98차 라이브 코테 제출
2 parents 5e91e0e + c178cd6 commit 86f0fea

3 files changed

Lines changed: 104 additions & 0 deletions

File tree

live9/test98/문제1/조진우.js

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
const fs = require("fs");
2+
const input = fs
3+
.readFileSync("./input.txt", "utf8")
4+
// .readFileSync("/dev/stdin", "utf8")
5+
.toString()
6+
.trim()
7+
.split("\n")
8+
.map((line) => line.split(" "));
9+
10+
function solution(input) {
11+
const [N, M] = input[0];
12+
const snow = input[1].map(Number);
13+
14+
let maxSize = 0;
15+
let count = 0; // 디버깅용
16+
17+
function dfs(position, time, size) {
18+
count++;
19+
// console.log("count:", count, [position, time, size, maxSize]); // 디버깅용
20+
if (time > M) return;
21+
// 시간 초과 시 종료
22+
if (size > maxSize) maxSize = size; // 최대값 갱신
23+
24+
if (position + 1 < N) {
25+
dfs(position + 1, time + 1, size + snow[position + 1]);
26+
}
27+
if (position + 2 < N) {
28+
dfs(position + 2, time + 1, Math.trunc(size / 2) + snow[position + 2]);
29+
}
30+
}
31+
32+
dfs(-1, 0, 1);
33+
34+
return maxSize;
35+
}
36+
37+
console.log(solution(input));

live9/test98/문제2/조진우.js

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
const fs = require("fs");
2+
const input = fs
3+
.readFileSync("./input.txt", "utf8")
4+
// .readFileSync("/dev/stdin", "utf8")
5+
.toString()
6+
.trim();
7+
8+
function solution(input) {
9+
// 숫자 배열화
10+
const numArr = input.split("");
11+
12+
// 뒤에서 부터 감소하는 index 찾기
13+
let index = numArr.length - 2;
14+
while (index >= 0 && numArr[index] >= numArr[index + 1]) {
15+
index--;
16+
}
17+
18+
// 만약 감소하는 부분이 없다면 0을 반환
19+
if (index < 0) return 0;
20+
21+
// numArr[index] 보단 크고 가장 뒤에있는 값 j에 저장
22+
let j = numArr.length - 1;
23+
while (numArr[index] >= numArr[j]) {
24+
j--;
25+
}
26+
27+
// 만약 numArr[index]보다 큰 값이 없다면 0을 반환
28+
if (j < 0) return 0;
29+
30+
// 두 숫자 자리 바꾸기
31+
[numArr[index], numArr[j]] = [numArr[j], numArr[index]];
32+
33+
// numArr[index] 뒤의 내용 자르고 reverse
34+
const sliceReversed = numArr.slice(index + 1).reverse();
35+
36+
// 자른 부분 붙히기
37+
numArr.splice(index + 1, sliceReversed.length, ...sliceReversed);
38+
39+
// 최종 배열 숫자화
40+
return numArr.join("");
41+
}
42+
43+
console.log(solution(input));

live9/test98/문제3/조진우.js

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
function solution(prices) {
2+
const answer = [];
3+
4+
for (let i = 0; i < prices.length; i++) {
5+
let seconds = 0;
6+
let j = i + 1;
7+
8+
while (true) {
9+
if (j >= prices.length) break;
10+
11+
seconds++;
12+
13+
if (prices[j] < prices[i]) break;
14+
15+
j++;
16+
}
17+
18+
answer.push(seconds);
19+
}
20+
21+
return answer;
22+
}
23+
24+
console.log(solution([1, 2, 3, 2, 3]));

0 commit comments

Comments
 (0)