seowon98 2020. 4. 15. 21:33

import java.util.*;
import java.io.*;

class Main{
    public static void main(String args[]) throws Exception{
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        int n = Integer.parseInt(br.readLine());
        
        HashSet hash = new HashSet();//중복 제거를 위해 hashset으로 입력받기
        
        for(int i=0;i<n;i++){
            set.add(br.readLine()); //입력 받기
        }
        
        ArrayList list = new ArrayList(set); //list로 변환 (set)
        
        //자바는 기본 정렬 다르게 하기 위해 comparator클래스 정의
        Collections.sort(list,new Comparator()){
            public int compare(String a, String b){
                if(a.length()>b.length()) return 1;//양수면 자리 바뀜
                else if(a.length()<b.length()) return -1; //음수또는 0이면 그대로
                else return a.compareTo(b);
            }
        });
        
        for(String s:list){
            System.out.println(s);
        }
    }
}