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

 

10814번: 나이순 정렬

온라인 저지에 가입한 사람들의 나이와 이름이 가입한 순서대로 주어진다. 이때, 회원들을 나이가 증가하는 순으로, 나이가 같으면 먼저 가입한 사람이 앞에 오는 순서로 정렬하는 프로그램을

www.acmicpc.net

const fs = require('fs');
let input = fs.readFileSync('/dev/stdin').toString().split("\n");

const N = Number(input[0]);
let arr = [];

for(let i = 1 ;i <= N ; i++) {
    const [ age, name ] = input[i].split(' ');
    arr.push([Number(age), name]);
}

arr.sort(function(a,b) {
    if(a[0] > b[0]) return 1;
    else if(a[0] < b[0]) return -1;
    else return 0;
})

arr = arr.map((a) => a[0]+" "+a[1]);

console.log(arr.join('\n'));
728x90

+ Recent posts