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