Solved.ac class2++
public class Main {
public static void main(String[] args) throws Exception{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int sum = 0;
int size = Integer.parseInt(br.readLine());
if (size == 0) {
System.out.println(0);
return;
}
ArrayList<Integer> array = new ArrayList<>();
for (int i = 0; i < size; i++) {
array.add(Integer.parseInt(br.readLine()));
}
int truncation = Math.round((float)size / 100 * 15);
array.sort(Comparator.naturalOrder());
removeTruncation(truncation, array);
for (Integer e : array) {
sum += e;
}
System.out.println(Math.round((float)sum / array.size()));
}
private static void removeTruncation(int truncation, ArrayList<Integer> array) {
for (int i = 0; i < truncation; i++) {
array.remove(0);
array.remove(array.size()-1);
}
}
}
시간초과
시간초과. ArrayList를 배열로 변경
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Arrays;
public class Main {
public static void main(String[] args) throws Exception{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int sum = 0;
int size = Integer.parseInt(br.readLine());
if (size == 0) {
System.out.println(0);
return;
}
int[] array = new int[size];
for (int i = 0; i < size; i++) {
array[i] = Integer.parseInt(br.readLine());
}
int truncation = Math.round((float)size / 100 * 15);
Arrays.sort(array);
for (int i = truncation; i < size - truncation; i++) {
sum += array[i];
}
System.out.println(Math.round((float)sum / (size - (2 * truncation))));
}
}
성공