Java实现
import java.util.*;
public class Main {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int n = in.nextInt();
//flag为1则n为奇数,为0则n为偶数
int flag = n&1;
int max,min;
double mid;
int[] arr = new int[n];
for(int i=0;i<n;i++){
arr[i] = in.nextInt();
}
if (arr[0]<=arr[n-1]){
max = arr[n-1];
min = arr[0];
}else{
min = arr[n-1];
max = arr[0];
}
//偶数个
if (flag==0){
mid = (arr[n/2]+arr[n/2-1])/2.0;
if ((mid-(int)mid)>0){
System.out.println(max+" "+mid+" "+min);
}else{
System.out.println(max+" "+(int)mid+" "+min);
}
}else{
mid = arr[n/2];
System.out.println(max+" "+(int)mid+" "+min);
}
in.close();
}
}