输入输出样例
样例1
输入
3
-1 2 4
输出
4 2 -1
样例2
输入
4
-2 -1 3 4
输出
4 1 -2
题解一
模拟。100分。
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
public class Main {
public static void main(String[] args) throws IOException {
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
int n = Integer.parseInt(reader.readLine().trim());
int max;
int min;
String[] strs = reader.readLine().trim().split(" ");
int num1 = Integer.parseInt(strs[0]);
int num2 = Integer.parseInt(strs[n - 1]);
max = Math.max(num1, num2);
min = Math.min(num1, num2);
if (n % 2 == 1) {
System.out.println(max + " " + Integer.parseInt(strs[n / 2]) + " " + min);
} else {
num1 = Integer.parseInt(strs[n / 2 - 1]);
num2 = Integer.parseInt(strs[n / 2]);
if ((num1 + num2) % 2 == 0) {
System.out.println(max + " " + (num1 + num2) / 2 + " " + min);
} else {
System.out.printf("%d %.1f %d", max, (num1 + num2) / 2.0, min);
}
}
}
}