Skip to content

Commit f6fb0af

Browse files
committed
알고리즘 풀이 업데이트
1 parent 1fec7d7 commit f6fb0af

File tree

4 files changed

+75
-0
lines changed

4 files changed

+75
-0
lines changed

part1/12.평균.txt

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
const fs=require("fs")
2+
const input=fs.readFileSync("index.txt").toString().split("\n")
3+
4+
// 점수/M*100
5+
6+
const cnt = Number(input[0])
7+
8+
let arr=input[1].split(" ").map(Number)
9+
10+
let maxValue=Math.max(...arr)
11+
12+
let maxValue=arr.reduce((a,b)=>Math.max(a,b))
13+
14+
console.log(maxValue)
15+
16+
let sum=0;
17+
for(let item of arr){
18+
sum+=item/maxValue*100
19+
}
20+
21+
console.log(sum/cnt)

part3/1.세수정렬.txt

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
const fs = require("fs")
2+
const input = fs.readFileSync("index.txt").toString().split("\n")
3+
4+
5+
const arr = input[0].split(" ")
6+
7+
const sortedArr = arr.sort(((a, b) => a - b))
8+
9+
let answer=""
10+
for(let i=0;i<sortedArr.length;i++){ answer+=sortedArr[i]+" "
11+
12+
}
13+
14+
console.log(answer)

part3/2.수정렬하기.txt

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
const fs = require("fs")
2+
const input = fs.readFileSync("index.txt").toString().split("\n")
3+
4+
5+
6+
let num=Number(input[0])
7+
let arr=[]
8+
9+
for(let i=1;i<=num;i++){
10+
arr.push(Number(input[i]))
11+
}
12+
13+
14+
15+
const sortedArr= arr.map(Number).sort((a,b)=>a-b)
16+
17+
let answer=""
18+
19+
for(let i=0;i<sortedArr.length;i++){
20+
answer+=sortedArr[i]+"\n"
21+
}
22+
23+
console.log(answer)
24+
25+
26+
27+
28+

part3/3.k번째수.txt

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
const fs = require("fs")
2+
const input = fs.readFileSync("index.txt").toString().split("\n")
3+
4+
5+
const num=Number(input[0].split(" ")[0])
6+
const k=Number(input[0].split(" ")[1])
7+
const arr=input[1].split(" ").map(Number)
8+
9+
10+
const sorted=arr.sort((a,b)=>a-b)
11+
12+
console.log(sorted[k-1])

0 commit comments

Comments
 (0)