输入输出样例

样例1

输入

  1. 3
  2. -1 2 4

输出

  1. 4 2 -1

样例2

输入

  1. 4
  2. -2 -1 3 4

输出

  1. 4 1 -2

题解一

模拟。100分。

  1. import java.io.BufferedReader;
  2. import java.io.IOException;
  3. import java.io.InputStreamReader;
  4. public class Main {
  5. public static void main(String[] args) throws IOException {
  6. BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
  7. int n = Integer.parseInt(reader.readLine().trim());
  8. int max;
  9. int min;
  10. String[] strs = reader.readLine().trim().split(" ");
  11. int num1 = Integer.parseInt(strs[0]);
  12. int num2 = Integer.parseInt(strs[n - 1]);
  13. max = Math.max(num1, num2);
  14. min = Math.min(num1, num2);
  15. if (n % 2 == 1) {
  16. System.out.println(max + " " + Integer.parseInt(strs[n / 2]) + " " + min);
  17. } else {
  18. num1 = Integer.parseInt(strs[n / 2 - 1]);
  19. num2 = Integer.parseInt(strs[n / 2]);
  20. if ((num1 + num2) % 2 == 0) {
  21. System.out.println(max + " " + (num1 + num2) / 2 + " " + min);
  22. } else {
  23. System.out.printf("%d %.1f %d", max, (num1 + num2) / 2.0, min);
  24. }
  25. }
  26. }
  27. }