对大模拟抱有深深的恐惧……不过这次写好像还好?拿个栈维护一下循环的嵌套,然后重定义一下读入即可。记得去年在考场上面死活调不粗来,代码也奇丑无比……希望今年能好一点吧!

#include <bits/stdc++.h>
using namespace std;
#define maxn 100000
int L, mark[maxn];
char ans[maxn]; int fread(int t)
{
int x = , k = ;
char c; c = ans[t]; t ++;
while(t < strlen(ans) && (c < '' || c > ''))
{
if(c == '-') k = -;
if(c == 'n') x = ;
c = ans[t]; t ++;
}
while(t < strlen(ans) && c >= '' && c <= '')
x = x * + c - '', c = ans[t], t ++;
return x * k;
} int read()
{
int x = , k = ;
char c; c = getchar();
while(c < '' || c > '')
{
if(c == '-') k = -;
if(c == 'n') { x = ; return x; }
c = getchar();
}
while(c >= '' && c <= '') x = x * + c - '', c = getchar();
return x * k;
} struct node
{
char c; int num;
node(char _c = 'z' + , int _num = )
{ c = _c, num = _num; }
}S[maxn]; void Work()
{
memset(mark, , sizeof(mark));
int cal = , top = , cnt = , err = , flag = ;
for(int i = ; i <= L; i ++)
{
char c; cin >> c;
if(c == 'F')
{
char x; cin >> x;
if(mark[x - 'a']) flag = ;
int l = read(), r = read();
mark[x - 'a'] = ;
if(r - l > && !err) cnt ++, cal = max(cal, cnt);
if(l > r) err ++;
S[++ top] = node(x, r - l);
}
else
{
if(!top) { flag = ; continue; }
mark[S[top].c - 'a'] = ;
if(!err) cnt -= S[top].num > ;
if(S[top].num < ) err --;
top --;
}
}
int len = strlen(ans), tag = , t = ;
for(int i = ; i < len; i ++)
if(ans[i] == 'n') tag = i + ;
else if(tag && i == tag) { t = fread(i); break; }
if(top) flag = ;
if(flag) { printf("ERR\n"); return; }
if(cal != t) flag = ;
if(flag) { printf("No\n"); return; }
printf("Yes\n"); return;
} int main()
{
int T; scanf("%d", &T);
while(T --)
{
scanf("%d %s", &L, ans);
Work();
}
return ;
}
05-11 21:44