Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include<stack>
- using namespace std;
- int main()
- {
- int n;
- char a;
- cin>>n;
- stack <int> S;
- S.push(4);
- for (int i=0;i<n;i++)
- {
- cin>>a;
- switch(a)
- {
- case '{':
- S.push(1);
- break;
- case '(':
- S.push(2);
- break;
- case '[':
- S.push(3);
- break;
- case ')':
- if (S.top()!=2)
- {
- cout<<"No";
- return 0;
- }
- S.pop();
- break;
- case '}':
- if (S.top()!=1)
- {
- cout<<"No";
- return 0;
- }
- S.pop();
- break;
- case ']':
- if (S.top()!=3)
- {
- cout<<"No";
- return 0;
- }
- S.pop();
- break;
- }
- }
- if (S.top()==4)
- cout<<"Yes";
- else cout<<"No";
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement