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