UVA 10041 Java

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

留言

這個網誌中的熱門文章

C# 井字遊戲