문제링크
https://www.acmicpc.net/problem/1181
나의코드
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.IOException;
import java.util.Arrays;
import java.util.Comparator;
public class Main{
public static void main(String[] args) throws IOException{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int num = Integer.parseInt(br.readLine());
String[] arr = new String[num];
for(int i = 0; i < num; i++){
arr[i] = br.readLine();
}
Arrays.sort(arr, new Comparator<String>(){
public int compare(String str1, String str2){
if(str1.length() == str2.length()){
return str1.compareTo(str2);
}else{
return str1.length() - str2.length();
}
}
});
StringBuilder sb = new StringBuilder();
sb.append(arr[0]).append('\n');
for(int i = 1; i < num; i++){
if(!arr[i].equals(arr[i - 1])){
sb.append(arr[i]).append('\n');
}
}
System.out.print(sb);
}
}
'Baekjoon Online Judge' 카테고리의 다른 글
[BOJ] 백준 1436번: 영화감독 숌 (Java) (0) | 2023.04.02 |
---|---|
[BOJ] 백준 1259번: 팰린드롬수 (Java) (0) | 2023.04.01 |
[BOJ] 백준 1018번: 체스판 다시 칠하기 (Java) (0) | 2023.03.30 |
[BOJ] 백준 1085번: 직사각형에서 탈출 (Java) (0) | 2023.03.29 |
[BOJ] 백준 2920번: 음계 (Java) (0) | 2023.03.28 |
댓글