You will be fine

<Algorithm> 138. K번째 접미어(SWExpert)

by BFine
반응형

1. K번째 접미어(SWExpert)

  • 정렬 문제

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
import java.util.Collections;
import java.util.LinkedList;
import java.util.List;
import java.util.Scanner;
import java.util.stream.Collectors;
 
public class Solution {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        /******************************
         * sort를 이용해서 n번째 단어를 찾는다.
         *******************************/
        int T = sc.nextInt();
        
        for(int t= 1; t <= T; t++ ) {
            
            int n = sc.nextInt();
            String str = sc.next();
            List<String> list = new LinkedList<>(); 
            
            for(int i = 0; i < str.length(); i++) {
                list.add(str.substring(i));
            }
            
        List<String> sort= list.stream()
                .sorted()
                .limit(n)
                .collect(Collectors.toList());
         System.out.println("#"+t+" "+sort.get(sort.size()-1));
        }
    }
}
 
cs



참고 & 출저


반응형

블로그의 정보

57개월 BackEnd

BFine

활동하기