0_0_39790986_12260\Main.java:1: 错误: 解析时已到达文件结尾
import java.util.*; public class Main { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); int T = scanner.nextInt(); // 读取测试组数 for (int t = 0; t < T; t++) { int N = scanner.nextInt(); // 盘子的数量 int m = scanner.nextInt(); // A柱上的盘子数量 int p = scanner.nextInt(); // B柱上的盘子数量 int q = scanner.nextInt(); // C柱上的盘子数量 if (m + p + q != N) { System.out.println("false"); continue; } List a = new ArrayList<>(); List b = new ArrayList<>(); List c = new ArrayList<>(); for (int i = 0; i < m; i++) { a.add(scanner.nextInt()); } for (int i = 0; i < p; i++) { b.add(scanner.nextInt()); } for (int i = 0; i < q; i++) { c.add(scanner.nextInt()); } System.out.println(isValidHanoiSequence(N, a, b, c)); } scanner.close(); } private static boolean isValidHanoiSequence(int N, List a, List b, List c) { Stack source = new Stack<>(); Stack auxiliary = new Stack<>(); Stack destination = new Stack<>(); for (int i = N - 1; i >= 0; i--) { source.push(i + 1); } for (int disk : a) { if (!source.isEmpty() && source.peek() == disk) { source.pop(); destination.push(disk); } else { return false; } } for (int disk : b) { if (!destination.isEmpty() && destination.peek() == disk) { destination.pop(); auxiliary.push(disk); } else if (!source.isEmpty() && source.peek() == disk) { source.pop(); auxiliary.push(disk); } else { return false; } } for (int disk : c) { if (!auxiliary.isEmpty() && auxiliary.peek() == disk) { auxiliary.pop(); destination.push(disk); } else { return false; } } return destination.size() == N; } }
^
1 个错误
|