boj - 11656 접미사 배열(자바)

SlowAnd·2024년 1월 1일
0

https://www.acmicpc.net/problem/11656

public class boj_11656 {
    public static void main(String[] args) throws IOException {
        BufferedReader r = new BufferedReader(new InputStreamReader(System.in));
        List<String> read = Arrays.stream(r.readLine().split("")).collect(Collectors.toList());
        List<String> box = new ArrayList<>();
        int size = read.size();
        for(int i =0; i<size ; i++){
            box.add(read.stream().skip(i).collect(Collectors.joining()));
        }
        box.sort(Comparator.naturalOrder());
        box.forEach(System.out::println);
    }
}

람다 스트림 잘 활용하기

public class boj_11656 {
    public static void main(String[] args) throws IOException {
        BufferedReader r = new BufferedReader(new InputStreamReader(System.in));
        String input = r.readLine();

        IntStream.range(0, input.length())
                 .mapToObj(i -> input.substring(i))
                 .sorted()
                 .forEach(System.out::println);
    }
}

더더 람다 스트림 잘 활용하기

package boj;

import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.util.Arrays;
import java.util.stream.Collectors;
import java.util.stream.IntStream;

public class boj_11656 {
    public static void main(String[] args) throws IOException {
        BufferedReader r = new BufferedReader(new InputStreamReader(System.in));
        BufferedWriter w = new BufferedWriter(new OutputStreamWriter(System.out));
        String input = r.readLine();

        String result = IntStream.range(0, input.length())
                .mapToObj(i -> input.substring(i))
                .sorted()
                .collect(Collectors.joining("\n"));
        w.write(result);
        w.flush();

    }
}

0개의 댓글