728x90

https://www.acmicpc.net/problem/2750

Code

최종 제출 코드

😢 기본 문제

😊 JavaScript built-in method인 sort()를 사용해주면 된다.
문자를 정렬할 때는 sort()를 그냥 써줘도 되지만, 숫자를 정렬할 때는 sort((a, b) => a-b); 로 써줘야 한다.
난 for ... of를 사용하고 좋아하지만, 속도(?)와 참고하는 사람들 때문에 정석 버전으로 캡쳐했다.

Full Code (https://github.com/DasolPark/Dasol_JS_Algorithm/tree/master/Baekjoon)

// Sort numbers(Ascending order)
 
// For submit
 
// const fs = require('fs');
// const input = fs.readFileSync('/dev/stdin').toString().trim().split('\n').map(num => parseInt(num));
 
// For local test
const input = [5, 5, 2, 3, 4, 1];
const N = input.shift();
const sorted = input.sort((a, b) => a - b);
 
for (let i = 0; i < N; i++) {
console.log(sorted[i]);
}
 
// For submit
 
// const fs = require('fs');
// const input = fs.readFileSync('/dev/stdin').toString().trim().split('\n').map(num => parseInt(num));
 
// For local test
// const input = [5, 5, 2, 3, 4, 1];
// input.shift();
// const sorted = input.sort((a, b) => a - b);
 
// for (let num of sorted) {
// console.log(num);
// }

+ Recent posts