단어 정렬(1181)
단어의 순서를 정의하여 정렬하는 문제
Last updated
단어의 순서를 정의하여 정렬하는 문제
Last updated
i
im
it
no
but
more
wait
wont
yours
cannot
hesitateimport java.io.*;
import java.util.*;
public class Main{
public static void main(String[] args) throws IOException{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int N = Integer.parseInt(br.readLine());
String arr[] = new String[N];
for(int i=0; i<N; i++){
arr[i] = br.readLine();
}
Arrays.sort(arr, new Comparator<String>() {
@Override
public int compare(String o1, String o2) {
if(o1.length() == o2.length())
return o1.compareTo(o2);
else
return o1.length() - o2.length();
}
});
System.out.println(arr[0]);
for (int i = 1; i < arr.length; i++) {
if(arr[i].equals(arr[i-1]))
continue;
else
System.out.println(arr[i]);
}
}
}