#include<iostream>
#include<string>
using namespace std;
int main()
{
string st;
cin>>st;
int i,j,k;
k=st.length();
if(st[0]==']'||st[0]=='}'||st[0]==')'||k%2==1)
cout<<"no";
else
{
for(i=k-1; i>0; i--)
{
if(st[i]==']'&&st[i-1]=='['||st[i]==')'&&st[i-1]=='('||st[i]=='}'&&st[i-1]=='{')
{
st.erase(i-1,2);
}
k=st.length();
}
if(k==0)
cout<<"yes";
else
cout<<"no";
}
}
如何判断括号是否合法c++
最新推荐文章于 2024-05-05 17:07:31 发布