12345678910111213141516171819202122232425262728293031323334353637 |
- #include<bits/stdc++.h>
- using namespace std;
- int main()
- {
- int flag;
- stack<char> s;
- string str;
- while(cin>>str){
- flag=1;
- for(int i=0;i<str.size();i++){
- if(str[i]=='('||str[i]=='['||str[i]=='{'){
- s.push(str[i]);
- }
- else{
- if(!s.empty()){
- if((str[i]==')'&&s.top()=='(')||(str[i]==']'&&s.top()=='[')||(str[i]=='}'&&s.top()=='{')){
- s.pop();
- }
- else if((str[i]==')'&&!s.empty())||(str[i]==']'&&!s.empty())||(str[i]=='}'&&!s.empty())){
- flag=0;
- }
- }else{
- flag=0;
- }
- }
- }
- if(!s.empty()||flag==0){
- cout<<"NO"<<endl;
- }else{
- cout<<"YES"<<endl;
- }
- while(!s.empty()){
- s.pop();
- }
- str.clear();
- }
- }
|