#include<memory.h> #include<ctype.h> #include<iostream> using namespace std; const int N=1005; char s[N],t[N],b[N],l[N],r[N],var[N]; int top,mx,m,w,T,sta[N];bool err,vis[N]; int main(){ for(scanf("%d",&T);T--;mx=top=err=0,memset(vis,0,sizeof vis)){ scanf("%d%s\n",&m,t); if(t[2]==‘n‘) sscanf(t+4,"%d",&w);else w=0; for(int x,y;m--;){ gets(s); if(s[0]==‘E‘){ if(!top) err=true; else vis[var[top--]]=false; } else{ sscanf(s,"%*s%s%s%s",b,l,r); if(vis[b[0]]) err=true;vis[b[0]]=true; var[++top]=b[0]; if(isdigit(l[0])){ if(isdigit(r[0])){ sscanf(l,"%d",&x);sscanf(r,"%d",&y); if(x<=y) sta[top]=sta[top-1]; else sta[top]=-1e9; } else if(r[0]==‘n‘){ sta[top]=sta[top-1]+1; mx=max(mx,sta[top]); } } else if(l[0]==‘n‘){ if(r[0]==‘n‘) sta[top]=sta[top-1]; else sta[top]=-1e9; } } } if(err||top) puts("ERR");else if(mx==w) puts("Yes");else puts("No"); } return 0; }
原文:https://www.cnblogs.com/shenben/p/12489283.html