Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<bits/stdc++.h>
- using namespace std;
- int main()
- {
- int n; scanf("%d",&n);
- while(n--){
- stack<char> S;
- char a[100005];
- scanf(" %s",a);
- int l=strlen(a);
- for(int i=0;i<l;i++){
- if(S.empty() && !isalpha(a[i])) S.push(a[i]);
- else{
- if(a[i]=='(' || (a[i]==')' && S.top()!='(')) S.push(a[i]);
- else if(a[i]==')' && S.top()=='(') S.pop();
- else if(a[i]=='[' || (a[i]==']' && S.top()!='[')) S.push(a[i]);
- else if(a[i]==']' && S.top()=='[') S.pop();
- else if(a[i]=='{' || (a[i]=='}' && S.top()!='{')) S.push(a[i]);
- else if(a[i]=='}' && S.top()=='{') S.pop();
- }
- }
- if(S.empty()) printf("Yes\n");
- else printf("No\n");
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement