-
Notifications
You must be signed in to change notification settings - Fork 0
/
1181-2.java
42 lines (28 loc) · 943 Bytes
/
1181-2.java
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
40
41
42
import java.io.IOException;
import java.util.Arrays;
import java.util.Comparator;
import java.util.Scanner;
public class Main {
public static void main(String[] args) throws IOException{
Scanner sc=new Scanner(System.in);
int N=sc.nextInt();
String array[]=new String[N];
for(int i=0; i<N; i++) {
array[i]=sc.next();
}
Arrays.sort(array,new Comparator<String>(){//우선순위를 판단해주는 comparator 메소드
public int compare(String s1, String s2) {
if(s1.length()==s2.length())//만약 s1과 s2의 길이가 같은 경우 사전순으로 정렬
return s1.compareTo(s2);
else //그렇지 않은 경우에 짧은 순으로 정렬
return s1.length()-s2.length();
}
});
System.out.println(array[0]);
for(int i=1; i<array.length; i++) {
if(!array[i].equals(array[i-1])) { //중복 단어 제외 출력
System.out.println(array[i]);
}
}
}
}