const fs = require('fs');
const path = process.platform === 'linux' ? '/dev/stdin' : './data.txt';
const input = fs
.readFileSync(path)
.toString()
.trim()
.split('\n')
.map((x) => parseInt(x));
const solve = (input) => {
const count = input.shift();
input.sort((a, b) => a - b);
console.log(input.join('\n'));
};
solve(input);
ํ์ด... ๋ฐฑ์ค ๋ฌธ์ ํ๊ธฐ ์ ์ ์งง์ ๋ฌธ์ ์๋ด๋ฅผ ๋ณด๋ฉด
2750์ ๊ฒฝ์ฐ ๋ฒ๋ธ์ ๋ ฌ ๋๋ ์ ํ์ ๋ ฌ์ ์ด์ฉํด์ ํ๊ณ (์๊ฐ๋ณต์ก๋ : O(n^2))
2751์ ๊ฒฝ์ฐ ๋ณํฉ์ ๋ ฌ ๋๋ ํ์ ๋ ฌ์ ์ด์ฉํด์ ํ๊ธธ ์ถ์ฒํ๊ณ ์๋ค.(์๊ฐ๋ณต์ก๋ : O(nlogn))
ํ๋, ๋ณํฉ ๋ฐ ํ์ ๋ ฌ ๊ตฌํ ๋์ด๋๊ฐ ์์ผ๋ ๊ฐ ์ธ์ด์ ๋ด์ฅ๋ ์ ๋ ฌํจ์๋ฅผ ์ด์ฉํ ๊ฒ์ ์ถ์ฒํ๊ณ ์๋ค.
javascript์ ๊ฒฝ์ฐ sort()๋ฅผ ์ด์ฉํ์ฌ ์ ๋ ฌ ํ ๋ฐ๋ณต๋ฌธ์ ํตํ console.log๋ฅผ ํด๋ ์๊ฐ์ด๊ณผ๊ฐ ๋ฐ์ํ์๋ค.
์ด๋ฅผ ์ฐพ์๋ณด๋, console.log ์์ฒด์ ์คํ์ด ์ฌ๋ฌ๋ฒ ๋ฐ๋ณต๋์ด ์๊ฐ์ด๊ณผ๊ฐ ๋๋ ๊ฒ์ด์๊ณ
์์ ๊ฐ์ด join method๋ฅผ ํตํด console.log๋ฅผ ํ๋ฒ๋ง ์ฌ์ฉํ์๋ค.
2750๋ฒ์ ๋ค์ ํ์ด๋ด์ผ๊ฒ ๋ค!
'๐ JavaScript > ๋ฐฑ์ค' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
[JS] 10989 (0) | 2022.06.17 |
---|---|
[JS] 2750 - Bubble sort, Selection sort (0) | 2022.06.15 |
[JS] 2750 (0) | 2022.06.13 |
[JS] 7568 (0) | 2022.06.08 |
[JS] 2231 (0) | 2022.06.07 |