求助
查看原帖
求助
338147
01bit楼主2021/2/25 15:00
#include<iostream>
#include<cstdio>
#include<string>
#include<algorithm>
#include<stack>
using namespace std;
int t;
string code[101];
int sread(int &x,string str){
	int res=0,len=str.length();
	while(x<len&&(str[x]<'0'||'9'<str[x])){
		if(str[x]=='n'){
			x++;
			return 1000;
		}
		x++;
	}
	while('0'<=str[x]&&str[x]<='9'){
		res=res*10+str[x]-'0';
		x++;
	}
	return res;
}
int geto(string o){
	int res=0;
	int x=3;
	if(o[2]=='n')res=sread(x,o);
	else res=0;
	return res;
}
int check(int len){
	int res=0,now=0;
	int flag=-1;
	bool ins[26],ef[26];
	stack<int>s;
	for(int i=1;i<=len;i++){
		if(code[i][0]=='F'){
			int k=code[i][2]-'a';
			if(ins[k])return -1;
			int x=3,a=sread(x,code[i]),b=sread(x,code[i]);
			s.push(k);
			ins[k]=true;
			if(b<a&&flag==-1)flag=k;
			else{
				if(b-a>100&&flag==-1){
					now++;
					res=max(res,now);
					ef[k]=true;
				}
			}
		}
		if(code[i][0]=='E'){
			if(s.empty())return -1;
			int k=s.top();
			s.pop();ins[k]=false;
			if(flag==k)flag=-1;
			if(ef[k]){
				ef[k]=false;
				now--;
			}
		}
	}
	if(s.size())return -1;
	return res;
}
int main(){
	ios::sync_with_stdio(false);
	cin>>t;
	int len;
	while(t--){
		cin>>len;
		string o;
		cin>>o;
		getchar();
		for(int i=1;i<=len;i++)getline(cin,code[i]);
		int w=check(len);
		if(w==-1)puts("ERR");
		else{
			if(w==geto(o))puts("Yes");
			else puts("No");
		}
	}
	return 0;
}
2021/2/25 15:00
加载中...