java里面如果用scanner.nextInt()一个一个地去读一定会超时
我是用scanner.nextLine()把一行都读进来,然后split之后只取想要的(第一个,最后一个,和中间的一个或者两个)
java 满分代码
import java.util.Arrays;
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
int n = Integer.parseInt(scanner.nextLine());
String[] lines = scanner.nextLine().split(" ");
double[] res = new double[3];
res[0] = Double.parseDouble(lines[0]);
res[2] = Double.parseDouble(lines[n - 1]);
res[1] = Double.parseDouble(lines[n/2]);
if(n % 2 == 0){
res[1] += Double.parseDouble(lines[n/2-1]);
res[1] /= 2;
}
scanner.close();
Arrays.sort(res);
for(int i = res.length - 1; i >= 0; i--){
double number = res[i];
if((int)number == number){
System.out.print((int)number + " ");
} else{
System.out.print(String.format("%.1f ", number));
}
}
}
}