Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<bits/stdc++.h>
- using namespace std;
- int main()
- {
- string a;
- cin>>a;
- stack <char> s;
- for(int i=0; i<a.size(); i++)
- {
- if(a[i]=='('||a[i]=='{'||a[i]=='[')
- {
- s.push(a[i]);
- }
- else if(a[i]==')'||a[i]=='}'||a[i]==']')
- {
- if(s.empty()||(a[i]==')'&&s.top()!='(')||(a[i]=='}'&&s.top()!='{')||(a[i]==']'&&s.top()!='['))
- {
- cout<<"NO";
- return 0;
- }
- else
- s.pop();
- }
- }
- if(s.empty())
- cout<<"YES";
- else cout<<"NO";
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement