https://www.acmicpc.net/problem/11656
11656번: 접미사 배열
첫째 줄에 문자열 S가 주어진다. S는 알파벳 소문자로만 이루어져 있고, 길이는 1,000보다 작거나 같다.
www.acmicpc.net
배열로 정렬해도 되고 PQ를 이용해도 됩니다.
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.PriorityQueue;
public class Main {
static BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
static StringBuilder sb = new StringBuilder();
public static void main(String[] args) throws Exception {
String str = br.readLine();
PriorityQueue<String> pq = new PriorityQueue<>((o1, o2) -> {
return o1.compareTo(o2);
});
for (int i = 0; i < str.length(); i++) {
pq.offer(str.substring(i, str.length()));
}
while (!pq.isEmpty()) {
sb.append(pq.poll()).append("\n");
}
System.out.print(sb.toString());
}
}'OJ' 카테고리의 다른 글
| [BOJ] 7567 그릇 (JAVA) (0) | 2023.02.07 |
|---|---|
| [BOJ] 1357 뒤집힌 덧셈 (JAVA) (0) | 2023.02.06 |
| [BOJ] 10798 세로읽기 (JAVA) (0) | 2023.02.04 |
| [BOJ] 11655 ROT13 (JAVA) (0) | 2023.02.03 |
| [BOJ] 9093 단어 뒤집기 (JAVA) (0) | 2023.02.02 |