UVA 10041 Java
- import java.util.*;
- public class main{
- public static void main(String[] args) {
- Scanner sc = new Scanner(System.in);
- int times = sc.nextInt();
- for(int i = 0; i < times; i++)
- {
- int count = sc.nextInt();
- int[] datas = new int[count];
- for(int j = 0; j < count; j++)
- datas[j] = sc.nextInt();
- Arrays.sort(datas);
- int len = 0;
- for(int j = 0; j < count; j++)
- len += Math.abs(datas[j] - datas[j/2]);
- System.out.println(len);
- }
- }
- };
留言
張貼留言