java第2个没过,dalao求调
查看原帖
java第2个没过,dalao求调
1170590
XXDDDDD楼主2024/1/24 22:54
import java.math.BigInteger;
import java.util.Scanner;
import java.util.Stack;

public class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        long T = in.nextLong();

        while (T > 0) {
            Stack<BigInteger> stack = new Stack<>();
            long n = in.nextLong();
            for (long i = 0; i < n; i++) {
                String str = in.next();
                if (str.equals("push")) {
                    BigInteger x = in.nextBigInteger();
                    stack.push(x);
                } else if (str.equals("pop")) {
                    if (stack.empty()) {
                        System.out.println("Empty");
                    } else {
                        stack.pop();
                    }

                } else if (str.equals("query")) {
                    if (stack.empty()) {
                        System.out.println("Anguei!");
                    } else {
                        System.out.println(stack.peek());
                    }
                } else {
                    System.out.println(stack.size());
                }
            }
            T--;
        }
    }
}
2024/1/24 22:54
加载中...