给你看看我的第二题的思路,不知道思路是不是对的,但是自测用例没问题,就是不给过。。。 public static int testCount() { Scanner in = new Scanner(System.in); int[] testCount = new int[5]; for (int i = 0; i < 5; i++) { testCount[i] = in.nextInt(); } int sum = 0; for (int i = 0; i < testCount.length; i++) { int x, y, z; for (x = 0; x < 2; x++) { if (testCount[x] > 0) break; } for (y = 1; y < 4; y++) { if (x != y && testCount[y] > 0) { break; } } for (z = 3; z < 5; z++) { if (z != y && testCount[z] > 0) { break; } } if (minus(testCount, x, y, z >= 5 ? 4 : z)) sum++; } return sum; } private static boolean minus(int[] testCount, int x, int y, int z) { if (testCount[x] <= 0) { return false; } testCount[x]--; if (testCount[y] <= 0) { return false; } testCount[y]--; if (testCount[z] <= 0) { return false; } testCount[z]--; return true; }