Java 版本: public class T2Main { public static void main(String[] args) { Scanner in = new Scanner(System.in); while (in.hasNext()) { // 封装值 Integer num = in.nextInt(); in.nextLine(); Integer[] ws = new Integer[num]; for (int i = 0; i < num; i++) { ws[i] = in.nextInt(); } Arrays.sort(ws); Integer total = 0; Integer t = 0; for (Integer w : ws) { t ^= w; total += w; } if (t == 0) { System.out.println(total - ws[0]); } else { System.out.println(-1); } } } }