문제 출처: https://www.acmicpc.net/problem/1181



1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.Comparator;
 
public class Main {
    public static void main(String[] args) throws Exception {
        BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
        int N = Integer.parseInt(reader.readLine());
        String[] arr = new String[N]; // 가급적 ArrayList보다 Array를 사용하여 정렬하기
        
        for(int i=; i<N ; i++)
            arr[i] = reader.readLine(); // 입력 시에 중복을 제외하지 않고 정렬 후 제외시킴
        
        Arrays.sort(arr, new Comparator<String>() {
            @Override
            public int compare(String o1, String o2) {
                if(o1.length() > o2.length())
                    return 1;
                else if(o1.length() < o2.length())
                    return -1;
                else 
                    return o1.compareTo(o2);
            }
        });
        
        StringBuilder builder = new StringBuilder();
        String str = "";
        
        for(int i=; i<arr.length ; i++){
            if(!arr[i].equals(str)){
                builder.append(arr[i]).append("\n");
                str = arr[i];
            }
        }
        
        System.out.println(builder);
    }
}
cs


'Algorithm' 카테고리의 다른 글

백준 2581번: 소수  (0) 2018.10.21
백준 1978번: 소수 찾기  (0) 2018.10.21
백준 1427번: 소트인사이드  (0) 2018.10.20
백준 2108번: 통계학  (1) 2018.10.20
백준 10989번: 수 정렬하기 3  (0) 2018.10.20

+ Recent posts