0_0_39749310_1397\Main.java:1: 错误: 解析时已到达文件结尾
import java.util.Scanner;import java.util.LinkedList;import java.util.Queue;import java.util.Stack;public class main { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); int numTestCases = scanner.nextInt(); scanner.nextLine(); // 消耗换行符 for (int i = 0; i < numTestCases; i++) { // 读取命令数量和操作类型(FIFO 或 FILO) String[] input = scanner.nextLine().split(" "); int numCommands = Integer.parseInt(input[0]); String operationType = input[1]; Queue<Integer> fifoQueue = new LinkedList<>(); Stack<Integer> filoStack = new Stack<>(); for (int j = 0; j < numCommands; j++) { input = scanner.nextLine().split(" "); String command = input[0]; if (command.equals("IN")) { int number = Integer.parseInt(input[1]); if (operationType.equals("FIFO"))fifoQueue.offer(number); } else { filoStack.push(number); } } else if (command.equals("OUT")) { if (operationType.equals("FIFO")) { if (!fifoQueue.isEmpty()) { System.out.println(fifoQueue.poll()); } else { System.out.println("None"); } } else { if (!filoStack.isEmpty()) { System.out.println(filoStack.pop()); } else { System.out.println("None");
^
1 个错误
|