fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. int main(){
  4. string a;cin>>a;
  5. stack<char>b;
  6. for(char c:a){
  7. if(c=='('||c=='['||c=='{') b.push(c);
  8. else{
  9. if(b.empty()){cout<<"NO";return 0;}
  10. char d=b.top();b.pop();
  11. if((c==')'&&d!='(')||(c==']'&&d!='[')||(c=='}'&&d!='{')){
  12. cout<<"NO";return 0;
  13. }
  14. }
  15. }
  16. if(b.empty()) cout<<"YES"; else cout<<"NO";
  17. }
  18.  
Success #stdin #stdout 0.01s 5288KB
stdin
{()()[{} ]}
stdout
NO