文章
119
粉丝
0
获赞
166
访问
10.9k
#include<iostream>
#include<stack>
using namespace std;
string str;
stack<char> st;
bool check()
{
for(int i=0;i<str.size();i++)
{
if(str[i]=='('||str[i]=='[')
st.push(str[i]);
else
{
if(st.empty())
return false;
if(str[i]==']'&&st.top()!='[')
return false;
if(str[i]==')'&&st.top()!='(')
return false;
st.pop();
}
}
if(!st.empty())
return false;
return true;
}
int main()
{
cin>>str;
bool flag=check();
if(flag)
cout<<"YES";
else
cout<<"NO";
return 0;
}
登录后发布评论
暂无评论,来抢沙发