ABC282D求hack
  • 板块学术版
  • 楼主tybbs不是SCATZ
  • 当前回复7
  • 已保存回复7
  • 发布时间2022/12/24 22:49
  • 上次更新2023/10/24 06:43:00
查看原帖
ABC282D求hack
527303
tybbs不是SCATZ楼主2022/12/24 22:49
#include<bits/stdc++.h>
#define endl "\n"
using namespace std;
char s[300005];
bool mark[30];
struct tnode{
	bool f[30];
};
stack<tnode> ls;
int main(){
	ios::sync_with_stdio(0);
	cin.tie(0);cout.tie(0);
	string ps;getline(cin,ps); 
	int n=ps.size();
	for(int i=0;i<n;i++){
		s[i+1]=ps[i];
	}
	int l=0,r=0;
	tnode nt;
	for(int j=0;j<24;j++){
		nt.f[j]=0;
	}			
	ls.push(nt);
	for(int i=1;i<=n;i++){
		if(s[i]=='('){
			tnode nt;
			for(int j=0;j<24;j++){
				nt.f[j]=0;
			}			
			ls.push(nt);
		}
		else if(s[i]==')'){
			for(int j=0;j<24;j++){
				if(ls.top().f[j]){
					mark[j]=0;
				}
			}
			ls.pop();
		}
		else{
			if(!mark[s[i]-'a']){
				ls.top().f[s[i]-'a']=1;
				mark[s[i]-'a']=1;
			}
			else{
				cout<<"No";
				return 0;
			}
		}
	}
	cout<<"Yes";
	return 0;
} 
2022/12/24 22:49
加载中...