Endless00 @ 2024-12-28 17:56:23
import java.util.*;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
String s2 = sc.nextLine();
int i = Integer.parseInt(s2);
for (int t = 0; t < i; t++) {
String[] s = sc.nextLine().split(" ");
String o = s[1];
int cnt = 0, max = 0;
Stack<String> stack = new Stack<>();
Stack<Integer> cnts = new Stack<>();
for (int l = Integer.parseInt(s[0]); l > 0; l--) {
String[] c = sc.nextLine().split(" ");
if (cnt == -1) {
continue;
}
if (cnt == -2) {
if (c[0].equals("F")) {
if (stack.search(c[1]) != -1) {
cnt = -1;
} else {
stack.push(c[1]);
}
}
if (c[0].equals("E")) {
stack.pop();
}
continue;
}
if (c[0].equals("F")) {
if (stack.search(c[1]) != -1) {
cnt = -1;
} else {
stack.push(c[1]);
if (c[3].equals("n") && !c[2].equals("n")) {
cnt++;
max = Math.max(max, cnt);
cnts.push(1);
} else if (c[2].equals("n")) {
cnt = -2;
cnts.push(0);
} else {
cnts.push(0);
}
}
} else if (c[0].equals("E")) {
if (stack.isEmpty()) {
cnt = -1;
continue;
}
stack.pop();
cnt -= cnts.pop();
}
}
if (stack.isEmpty()) {
if (max == 0) {
if (o.equals("O(" + 1 + ")")) {
System.out.println("YES");
} else {
System.out.println("NO");
}
} else {
if (o.equals("O(n^" + max + ")")) {
System.out.println("YES");
} else {
System.out.println("NO");
}
}
} else {
System.out.println("ERR");
}
stack.clear();
cnts.clear();
}
}
}
by Zskioaert1106 @ 2025-01-01 15:57:24
@Endless00 注意看输出的格式