알고리즘 문제 풀이
[백준 알고리즘] javascript 나이순 정렬 10814번
호박고구마123
2024. 3. 24. 17:14
https://www.acmicpc.net/problem/10814
10814번: 나이순 정렬
온라인 저지에 가입한 사람들의 나이와 이름이 가입한 순서대로 주어진다. 이때, 회원들을 나이가 증가하는 순으로, 나이가 같으면 먼저 가입한 사람이 앞에 오는 순서로 정렬하는 프로그램을
www.acmicpc.net
const filePath = process.platform === "linux" ? "/dev/stdin" : "ex.txt";
const [n, ...lines] = require("fs")
.readFileSync(filePath)
.toString()
.trim()
.split("\n");
let users = [];
lines.forEach((line, index) => {
const [age, name] = line.split(" ");
users.push({ age: parseInt(age), name, index });
});
users.sort((a, b) => a.age - b.age);
users.forEach(({ age, name }) => {
console.log(`${age} ${name}`);
});