#include<bits/stdc++.h>
using namespace std;
int main() {
stack<char> s;
char c[1001];
while(~scanf("%s",c)) {
int len = strlen(c);
for(int i=0; i<len; i++) {
if(s.empty()){
s.push(c[i]);
continue;
}
if((c[i]==')' && s.top()=='('))
s.pop();
else if(c[i]=='}'&&s.top()=='{')
s.pop();
else if(c[i]==']'&&s.top()=='[')
s.pop();
else{
s.push(c[i]);
}
}
if(s.empty())
cout<<"YES"<<endl;
else
cout<<"NO"<<endl;
}
return 0;
}
1583: 括号匹配
最新推荐文章于 2023-03-28 21:09:49 发布