AT_abc394_d 题解
getchar_unlocked · · 题解
题目传送门
思路
在最基础的括号匹配问题上,变成了 No。最后再判断最后的栈是否为空(是否有多余的左括号)即可。
时间复杂度
AC CODE
#include<bits/stdc++.h>
using namespace std;
char to[128];
signed main(){
string s;cin>>s;
to[')']='(',to[']']='[',to['>']='<';
stack<char>st;
for(auto ch:s){
if(ch=='('||ch=='['||ch=='<')
st.push(ch);
else if(ch==')'||ch==']'||ch=='>'){
if(st.empty()||st.top()!=to[ch])
return cout<<"No\n",0;
st.pop();
}
else return cout<<"No\n",0;
}
if(st.empty())
cout<<"Yes\n";
else cout<<"No\n";
return 0;
}