题目链接:https://vjudge.net/contest/121192#problem/G
此题大意是给定一个数n 然后有n个数 要求求出其中位数 刚开始以为是按数学中的中位数当n为偶数时输出中间两位数之和再除以2 这题是只要先排序再输出第n/2个数即可
ac代码:
1 import java.io.BufferedInputStream; 2 import java.util.Arrays; 3 import java.util.Scanner; 4 5 public class Main { 6 public static void main(String[] args) { 7 Scanner s = new Scanner(new BufferedInputStream(System.in)); 8 9 while (s.hasNext()) { 10 int t = s.nextInt(); 11 int a[] = new int[t]; 12 for (int i = 0; i < t; i++) 13 a[i] = s.nextInt(); 14 Arrays.sort(a); //数组排序 15 16 System.out.println(a[t / 2]); 17 18 } 19 s.close(); 20 } 21 }