Skip to content

Commit 0fd6075

Browse files
authored
[PGS] 17683 [3차] 방금그곡 (Lv.2)
1 parent e23cd5d commit 0fd6075

File tree

1 file changed

+49
-0
lines changed

1 file changed

+49
-0
lines changed

박예진/0주차/구현/17683.js

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
// C, C#, D, D#, E, F, F#, G, G#, A, A#, B
2+
3+
function solve(str) {
4+
let res = "";
5+
for (let i = 0; i < str.length; i++) {
6+
if (str[i + 1] === "#") {
7+
res += str[i].toLowerCase();
8+
i++;
9+
} else {
10+
res += str[i];
11+
}
12+
}
13+
return res;
14+
}
15+
16+
function solution(m, musicinfos) {
17+
var answer = '';
18+
19+
m = solve(m);
20+
21+
// 시작, 끝, 제목, 악보
22+
let res = []; // 최종 후보들
23+
for(let i = 0; i < musicinfos.length; i++) {
24+
const [start, end, title, sheet] = musicinfos[i].split(",");
25+
26+
let s = Number(start.substr(0, 2)) * 60 + Number(start.substr(3, 2));
27+
let e = Number(end.substr(0, 2)) * 60 + Number(end.substr(3, 2));
28+
let time = e - s;
29+
let sheetNorm = solve(sheet);
30+
31+
// 악보 반복
32+
let str = "";
33+
for (let t = 0; t < time; t++) {
34+
str += sheetNorm[t % sheetNorm.length];
35+
}
36+
// 포함되면 최종 후보들 추가
37+
if (str.includes(m)) {
38+
res.push([time, title, i]);
39+
}
40+
}
41+
42+
if (res.length == 0) return "(None)";
43+
res.sort((a, b) => {
44+
if (a[0] != b[0]) return b[0] - a[0]; // sum 내림차순
45+
else return a[2] - b[2]; // idx 오름차순
46+
})
47+
48+
return res[0][1];
49+
}

0 commit comments

Comments
 (0)