|
沙发
楼主 |
发表于 2018-6-5 17:45:00
|
只看该作者
- #include <algorithm>
- #include <iostream>
- #include <cstring>
- #include <cstdio>
- using namespace std;
- int T,L,MX,CNT,top;
- bool ERR_;
- struct Node
- {
- int id,step;
- bool naive;
- } data[110];
- char s[10],s1[10],s2[10];
- bool use[30];
- inline int read()
- {
- int x=0;
- char ch=getchar();
- while(ch<'0'||ch>'9')
- ch=getchar();
- while(ch>='0'&&ch<='9')
- {
- x=x*10+ch-'0';
- ch=getchar();
- }
- return x;
- }
- int main()
- {
- //freopen("complexity.in","r",stdin);
- //freopen("complexity.out","w",stdout);
- T=read();
- while(T--)
- {
- MX=0;
- top=0;
- CNT=0;
- ERR_=false;
- memset(use,0,sizeof(use));
- L=read();
- scanf("%s",&s[0]);
- if(s[2]=='1')
- CNT=0;
- else for(int i=4; s[i]>='0'&&s[i]<='9'; i++)
- CNT=CNT*10+s[i]-'0';
- while(L--)
- {
- char ch=getchar();
- while(ch!='F'&&ch!='E')
- ch=getchar();
- if(ch=='E')
- {
- if(ERR_)
- continue;
- if(!top)
- ERR_=true;
- if(!ERR_)
- {
- use[data[top].id]=false;
- top--;
- }
- }
- else
- {
- while(ch<'a'||ch>'z')
- ch=getchar();
- if(!ERR_)
- {
- if(use[ch-'a'])
- ERR_=true;
- }
- if(!ERR_)
- {
- top++;
- data[top].id=ch-'a';
- use[data[top].id]=true;
- }
- for(int i=0; i<=3; i++)
- s1[i]=s2[i]='?';
- scanf("%s%s",&s1[0],&s2[0]);
- if(ERR_)
- continue;
- int L=0,R=0;
- if(s1[0]=='n')
- L=100;
- else for(int i=0; s1[i]>='0'&&s1[i]<='9'; i++)
- L=L*10+s1[i]-'0';
- if(s2[0]=='n')
- R=100;
- else for(int i=0; s2[i]>='0'&&s2[i]<='9'; i++)
- R=R*10+s2[i]-'0';
- if(L>R)
- data[top].naive=true;
- else data[top].naive=data[top-1].naive;
- if(L<100&&R==100&&!data[top].naive)
- data[top].step=data[top-1].step+1;
- else data[top].step=data[top-1].step;
- MX=max(MX,data[top].step);
- }
- }
- if(top)
- ERR_=true;
- if(ERR_)
- cout<<"ERR"<<endl;
- else if(MX==CNT)
- cout<<"Yes"<<endl;
- else cout<<"No"<<endl;
- }
- return 0;
- }
复制代码 |
|