Skip to content

Commit a138a72

Browse files
committed
알고리즘 풀이 업데이트
1 parent 30b20f2 commit a138a72

File tree

1 file changed

+37
-0
lines changed

1 file changed

+37
-0
lines changed

part4/7.피보나치.txt

+37
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
const fs = require("fs")
2+
const input = fs.readFileSync("/dev/stdin").toString().split("\n")
3+
4+
const num = Number(input[0])
5+
6+
let arr = [];
7+
8+
for (let i = 1; i <= num; i++) {
9+
arr.push(input[i])
10+
}
11+
12+
for (let i = 0; i < arr.length; i++) {
13+
// 피보나치 수열
14+
let pi=[1,1];
15+
let index=2;
16+
17+
while(true){
18+
let sum= pi[index-1]+pi[index-2]
19+
if(sum>arr[i]){
20+
break;
21+
}
22+
pi.push(sum)
23+
index++
24+
}
25+
26+
const answer=[];
27+
28+
let num=Number(arr[i])
29+
//
30+
for(let i=pi.length-1; i>=0;i--){
31+
if(num-pi[i]>=0){
32+
num=num-pi[i]
33+
answer.push(pi[i])
34+
}
35+
}
36+
console.log(answer.reverse().join(" "))
37+
}

0 commit comments

Comments
 (0)