백준 단계별
[Java] 백준 25305: 커트라인
pullwall
2023. 2. 2. 14:37
728x90
import java.util.*;
public class Main {
public static void main(String[] args){
Scanner sc = new Scanner(System.in);
int N = sc.nextInt();
int[] arr = new int[N];
int k = sc.nextInt();
for(int i=0 ; i<N ; i++){
arr[i] = sc.nextInt();
}
for(int i=0;i<N;i++){
int minindex=i;
for(int j=i+1;j<N;j++){
if(arr[minindex]>arr[j]){
minindex=j;
}
}
int tmp=arr[i];
arr[i]=arr[minindex];
arr[minindex]=tmp;
}
System.out.println(arr[N-k]);
}
}
https://welldonecode.tistory.com/73
[Java] 정렬 알고리즘 - 선택정렬(Selection Sort)
import java.util.Arrays; public class Main { public static void main(String[] args){ int[] arr = {7, 5, 9, 0, 3, 1, 6, 2, 4, 8}; for(int i=0; i
welldonecode.tistory.com
정렬 알고리즘으로 배열을 정렬한 후
5명중 2명을 뽑는다면 커트라인은 정렬했을때의 4번째 참가자의 성적이 되므로
arr[N-k]를 출력하면 된다.
728x90