Fork me on GitHub

NYOJ题目124中位数

-------------------------------------

 

排序取中间数即可

 

AC代码:

 1 import java.util.Arrays;
 2 import java.util.Scanner;
 3 
 4 public class Main {
 5 
 6     public static void main(String[] args) {
 7         
 8         Scanner sc=new Scanner(System.in);
 9         
10         int times=sc.nextInt();
11         while(times-->0){
12             int n=sc.nextInt();
13             int x[]=new int[n];
14             for(int i=0;i<x.length;i++) x[i]=sc.nextInt();
15             Arrays.sort(x);
16             System.out.println(x[x.length/2]);
17         }
18     }
19     
20 }

 

题目来源: http://acm.nyist.net/JudgeOnline/problem.php?pid=124

posted @ 2016-09-21 23:16  CC11001100  阅读(219)  评论(0编辑  收藏  举报