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

 

1181번: 단어 정렬

첫째 줄에 단어의 개수 N이 주어진다. (1 ≤ N ≤ 20,000) 둘째 줄부터 N개의 줄에 걸쳐 알파벳 소문자로 이루어진 단어가 한 줄에 하나씩 주어진다. 주어지는 문자열의 길이는 50을 넘지 않는다.

www.acmicpc.net

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

const n = Number(ip[0]);
ip.shift();

let input = new Set(ip);
input = Array.from(input);

input.sort(function(a,b) {
    if(a.length !== b.length) return a.length - b.length;
    else {
        return a > b ? 1 : -1;
    }
});

input.forEach((i, index) => {
    console.log(i);
});
728x90

+ Recent posts