반응형
📖 문제
📃 코드
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.Comparator;
public class Main {
public static BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
public static String word[];
public static void main(String[] args) throws IOException {
StringBuilder sb = new StringBuilder();
int N = Integer.parseInt(br.readLine());
word = new String[N];
for (int i = 0; i < N; i++) {
word[i] = br.readLine();
}
wordSort(word);
sb.append(word[0] + "\n");
for (int i = 1; i < N; i++) {
if (!word[i].equals(word[i - 1])) {
sb.append(word[i] + "\n");
}
}
System.out.println(sb);
}
public static void wordSort(String word[]) throws IOException {
Arrays.sort(word, new Comparator<String>() {
@Override
public int compare(String s1, String s2) {
if (s1.length() == s2.length()) {
return s1.compareTo(s2);
} else {
return s1.length() - s2.length();
}
}
});
}
}
🔗 링크
https://www.acmicpc.net/problem/1181
'Study & Project ✏️ > 알고리즘 📋' 카테고리의 다른 글
백준[JAVA] 1920.수 찾기 - 자바 (0) | 2022.10.09 |
---|---|
백준[JAVA] 7568.덩치 - 자바 (0) | 2022.10.07 |
백준[JAVA] 9012.괄호- 자바 (0) | 2022.10.06 |
백준[JAVA] 2231.분해합 - 자바 (1) | 2022.09.29 |
백준[JAVA] 10828.스택 - 자바 (0) | 2022.09.28 |