Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <cstdio>
- #include <cstring>
- #include <iostream>
- char s[130];
- char stack[130];
- int main(){
- //freopen("input.txt","r",stdin);
- int t=0;
- char c;
- while (scanf("%c", &c), c!='\n')
- t=10*t+c-'0';
- for (int i=0; i<t; i++){
- int n=0;
- while (scanf("%c", &c), c!='\n')
- s[n++]=c;
- if (n==0){
- printf("Yes\n");
- continue;
- }
- int nstack=0;
- bool win=true;
- for (int j=0; j<n; j++){
- c=s[j];
- if (c=='[' || c=='(')
- stack[nstack++]=c;
- else
- if (nstack==0){
- printf("No\n");
- win=false;
- break;
- }
- else{
- char last=stack[nstack-1];
- if (c==')' && last=='[' || c==']' && last=='('){
- printf("No\n");
- win=false;
- break;
- }
- else
- nstack--;
- }
- }
- if (win){
- if (nstack==0)
- printf("Yes\n");
- else
- printf("No\n");
- }
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment