문제
입력 및 출력
풀이
import java.io.*;
import java.util.*;
class Main {
public static void main(String args[]) throws Exception {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int T = Integer.parseInt(br.readLine());
StringBuilder sb = new StringBuilder();
for (int i = 0; i < T; i++) {
String[] temp = br.readLine().split(" ");
int[] array = new int[temp.length];
for (int j = 0; j < temp.length; j++) {
array[j] = Integer.parseInt(temp[j]);
}
sb.append(SelectionSort(array) + "\n");
}
System.out.println(sb);
}
public static int SelectionSort(int[] array) {
int minIndex = 0;
for (int i = 0; i < array.length; i++) {
minIndex = i;
for (int j = i + 1; j < array.length; j++) {
if (array[minIndex] > array[j]) {
minIndex = j;
}
}
int temp = array[i];
array[i] = array[minIndex];
array[minIndex] = temp;
}
return array[array.length - 3];
}
}
결과 및 해결방법
[결과]