const fs = require('fs');
const path = process.platform === 'linux' ? '/dev/stdin' : './data.txt';
const input = fs
.readFileSync(path)
.toString()
.trim()
.split('\n')
.map((number) => parseInt(number));
const solve = (input) => {
const count = input.shift();
const arr = input;
const ans = input.sort((a, b) => a - b);
for (let i = 0; i < ans.length; i++) {
console.log(ans[i]);
}
};
solve(input);
/* ๋ฒ๋ธ ์ํธ ๊ตฌํ
const fs = require('fs');
const path = process.platform === 'linux' ? '/dev/stdin' : './data.txt';
const input = fs
.readFileSync(path)
.toString()
.trim()
.split('\n')
.map((number) => parseInt(number));
const solve = (input) => {
let count = input.shift();
for (let i = count - 1; i > 0; i--) {
for (let j = 0; j < i; j++) {
if (input[j] > input[j + 1]) {
let a = input[j];
input[j] = input[j + 1];
input[j + 1] = a;
}
}
}
for (let num of input) {
console.log(num);
}
};
solve(input);
*/
๋๋์ด ์ ๋ ฌ!!! ๊ธฐ๋ณธ ๋ด์ฅํจ์์ธ sort๋ฅผ ์ฌ์ฉํ์ง๋ง, ๊ทธ ๋ค์ ๋ฒ๋ธ์ ๋ ฌ๋ก๋ ๊ตฌํํด๋ณด์๋ค.
ํ์คํ ์๋ฃ๊ตฌ์กฐ์ ์๊ณ ๋ฆฌ์ฆ์ด ์ค์ํ๋ค๊ณ ๋๋ผ๊ฒ ํด์ฃผ๋ ํํธ
'๐ JavaScript > ๋ฐฑ์ค' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
[JS] 2750 - Bubble sort, Selection sort (0) | 2022.06.15 |
---|---|
[JS] 2751 (0) | 2022.06.14 |
[JS] 7568 (0) | 2022.06.08 |
[JS] 2231 (0) | 2022.06.07 |
[JS] 2798 (0) | 2022.06.07 |