Notice
Recent Posts
Recent Comments
Link
์ผ | ์ | ํ | ์ | ๋ชฉ | ๊ธ | ํ |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | 6 | 7 |
8 | 9 | 10 | 11 | 12 | 13 | 14 |
15 | 16 | 17 | 18 | 19 | 20 | 21 |
22 | 23 | 24 | 25 | 26 | 27 | 28 |
29 | 30 | 31 |
Tags
- ๋ฐฑ์ค 2108 ์๋ฐ์คํฌ๋ฆฝํธ
- ๊ตฌ๋ฆํค
- TypeError: createContext only works in Client Components. Add the "use client" directive at the top of the file to use it. Read more:
- suspense ๋ณ๋ชฉํ์
- js ๊ฑฐ๋ฆฌ๋๊ธฐ ํ์ธํ๊ธฐ
- suspense ๋์์๋ฆฌ
- suspense ๋น๋๊ธฐ
- ๊ตฌ๋ฆํค ์ฑ๋ฆฐ์ง
- ์๋ฐ์คํฌ๋ฆฝํธ ์ค์ฝํ
- ๋ฆฌ์กํธ์ฟผ๋ฆฌ suspense
- ์ค์ฝํ
- ๊ตฌ๋ฆํค ์ฑ๋ฆฐ์ง ํ๊ณ
- emotion RSC
- next13 emotion
- ๋ฐฑ์ค 1339๋ฒ js
- js
- ์๋ฐ์คํฌ๋ฆฝํธ ๋ฌธ์์ด ์์ถ
- ์นด์นด์ค ์ฝํ
- js ๋ฌธ์์ด ์์ถ
- suspense react-query
- ์ต์ ๋์ฒด์ด๋
- ํ๋ก๊ทธ๋๋จธ์ค ๊ฑฐ๋ฆฌ๋๊ธฐ ํ์ธํ๊ธฐ
- ๋ฐฑ์ค 1339๋ฒ nodejs
- ๋ฐฑ์ค 2108 nodejs
- ํ๋ก๊ทธ๋๋จธ์ค ๋ฌธ์์ด ์์ถ
- app router emotion
- ์ฌ์ฉ์ฑ ๊ฐ์
- js ์ค์ฝํ
- ๋ฐฑ์ค 1339๋ฒ ์๋ฐ์คํฌ๋ฆฝํธ
- emtion app router
Archives
- Today
- Total
Lennon FE
[๋ฐฑ์ค 2108๋ฒ] ํต๊ณํ - ์๋ฐ์คํฌ๋ฆฝํธ(nodejs) ๋ณธ๋ฌธ
๐ฅ Algorithm/Algorithm Retrospect
[๋ฐฑ์ค 2108๋ฒ] ํต๊ณํ - ์๋ฐ์คํฌ๋ฆฝํธ(nodejs)
Lennon 2022. 1. 26. 00:42728x90
๋ฐ์ํ
https://www.acmicpc.net/problem/2108
const fs = require('fs');
let input = fs.readFileSync('dev/stdin').toString().trim().split('\n');
input.shift();
input = input.map((v) => +v).sort((a, b) => a - b);
// ํ๊ท
console.log(Math.round(input.reduce((prev, cur) => prev + cur, 0) / input.length));
// ์ค์๊ฐ
console.log(input[(input.length - 1) / 2]);
let obj = {};
for (let i = 0; i < input.length; i++) {
if (obj.hasOwnProperty(String(input[i]))) {
obj[String(input[i])] += 1;
} else {
obj[String(input[i])] = 1;
}
}
obj = Object.entries(obj).sort(([a, b], [c, d]) => {
if (b === d) {
return a - c;
} else {
return d - b;
}
});
if (obj.length === 1) {
console.log(obj[0][0]);
} else if (obj[0][1] === obj[1][1]) {
console.log(obj[1][0]);
} else {
console.log(obj[0][0]);
}
// ์ต๋น๊ฐ
// ๋ฒ์
console.log(Math.abs(Math.max(...input) - Math.min(...input)));
์ต๋น๊ฐ์ ๊ฐ์ฒด๋ฅผ ์ฌ์ฉํด hasOwnProperty๋ฅผ ์ด์ฉํด ๊ฐ์๋ฅผ ์ฝ๊ฒ ๊ตฌํด์ฃผ๊ณ , ํด๋น ๊ฐ์ฒด๋ฅผ ๋ฐฐ์ด๋ก ๋ค์ ๋ณํ ํ ์ ๋ ฌํด์ค๋ค.
728x90
๋ฐ์ํ
'๐ฅ Algorithm > Algorithm Retrospect' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
๋ฐฐ์ด์์๋ join("").substring() ๋์ slice().join("")์ (0) | 2021.11.05 |
---|
Comments