Created
          December 30, 2019 16:52 
        
      - 
      
- 
        Save dalcon10028/df9968e0b86da8bc4534229bca672983 to your computer and use it in GitHub Desktop. 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | import java.util.*; | |
| public class Main { | |
| public static void main(String[] args) { | |
| Scanner sc = new Scanner(System.in); | |
| StringBuilder sb = new StringBuilder(); // 출력이 많으므로 사용합니다. | |
| int N = sc.nextInt(); | |
| TreeSet<String> treeWords = new TreeSet<String>(); // 트리셋을 사용하여 자동중복 제거 | |
| for (int i=0; i<N; i++) | |
| treeWords.add(sc.next()); | |
| sc.close(); | |
| ArrayList<String> words = new ArrayList<String>(treeWords); // 중복 제거된 리스트를 다시 담기 | |
| Collections.sort(words, new Comparator<String>() { | |
| @Override | |
| public int compare(String a, String b){ | |
| return a.length() == b.length() ? a.compareTo(b) : a.length()-b.length() ; // 길이가 같으면 사전식 비교 다르면 길이 비교 | |
| } | |
| }); | |
| for (String string : words) { | |
| sb.append(string+"\n"); | |
| } | |
| System.out.print(sb); | |
| } | |
| } | 
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment