82pts求助
查看原帖
82pts求助
598875
nikodo楼主2023/11/26 10:37

借鉴了题解的思路,为啥不对?

#include<bits/stdc++.h>
using namespace std;
int l,fz;
string s,code[105];
stack<int> st,emp;
int check(){
	st=emp;//清空
	bool mp[26]={0},gx[26]={0};
	int maxn=0,now=0;
	int flag=-1;
	for(int i=1;i<=l;i++){
		if(code[i][0]=='F'){
			int k=code[i][2]-'a';
			if(mp[k])return -1;
			st.push(k);
			mp[k]=1;
			int a=0,b=0,point=4;
			while(code[i][point]>='0'&&code[i][point]<='9'){
				a=a*10+(code[i][point++]-'0');
			}
			if(code[i][point]=='n')a=1e9;
			point++;
			int len=code[i].length();
			while(point<len&&code[i][point]>='0'&&code[i][point]<='9'){
				b=b*10+(code[i][point++]-'0');
			}
			if(code[i][point]=='n')b=1e9;
			if(b-a>=1000){
				if(flag==-1){
					now++;
					if(now>maxn)maxn=now;
					gx[k]=1;
				}
			}
			if(a>b){
				if(flag==-1)flag=k;
			}
		}else{
			if(st.empty())return -1;
			int k=st.top();
			st.pop();
			mp[k]=0;
			if(flag==k)flag=-1;
			if(gx[k]){
				gx[k]=0;
				now--;
			}
		}
	}
	if(st.size())return -1;
	return maxn;
}
void solve(){
	cin>>l;
	getline(cin,s);
	if(s[3]=='n'){
		fz=0; 
		for(int i=5;i<s.length()-1;i++)fz=fz*10+(s[i]-'0');
	}else fz=0;
	cout<<fz<<'\n';
	for(int i=1;i<=l;i++)getline(cin,code[i]);
	int tmp=check();
	if(tmp==-1)cout<<"ERR\n";
	else if(tmp==fz)cout<<"Yes\n";
	else cout<<"No\n";
	return;
}
int main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	int T;
	cin>>T;
	while(T--)solve();
	return 0;
}
2023/11/26 10:37
加载中...