文章
3
粉丝
40
获赞
1
访问
1.6k
#include <iostream>
#include <stack>
#include <string>
using namespace std;
int main(){
stack<char> c;
string s;
cin >> s;
for(int i = 0;i < s.size();i++)
{
if(s[i] == '(' || s[i] == '[' )
{
c.push(s[i]);
}
else if(s[i] == ']')
{
if(!c.empty() && c.top() == '[') c.pop();
else c.push(s[i]);
}
else if(s[i] == ')')
{
if(!c.empty() && c.top() == '(') c.pop();
else c.push(s[i]);
}
}
if(c.empty()) printf("YES");
else printf("NO");
return 0;
}
登录后发布评论
暂无评论,来抢沙发