Guest User

Untitled

a guest
Nov 18th, 2012
326
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.23 KB | None | 0 0
  1. #include <cstdio>
  2. #include <cstring>
  3. #include <iostream>
  4.  
  5. char s[130];
  6. char stack[130];
  7.  
  8. int main(){
  9.    //freopen("input.txt","r",stdin);
  10.    int t=0;
  11.    char c;
  12.    while (scanf("%c", &c), c!='\n')
  13.        t=10*t+c-'0';
  14.    for (int i=0; i<t; i++){
  15.        int n=0;
  16.        while (scanf("%c", &c), c!='\n')
  17.            s[n++]=c;
  18.        if (n==0){
  19.            printf("Yes\n");
  20.            continue;
  21.        }
  22.        int nstack=0;
  23.        bool win=true;
  24.        for (int j=0; j<n; j++){
  25.            c=s[j];
  26.            if (c=='[' || c=='(')
  27.                stack[nstack++]=c;
  28.            else
  29.                if (nstack==0){
  30.                    printf("No\n");
  31.                    win=false;
  32.                    break;
  33.                }
  34.                else{
  35.                    char last=stack[nstack-1];
  36.                    if (c==')' && last=='[' || c==']' && last=='('){
  37.                        printf("No\n");
  38.                        win=false;
  39.                        break;
  40.                    }
  41.                    else
  42.                        nstack--;
  43.                }
  44.        }
  45.        if (win){
  46.            if (nstack==0)
  47.                printf("Yes\n");
  48.            else
  49.                printf("No\n");
  50.        }
  51.    }
  52.    return 0;
  53. }
Advertisement
Add Comment
Please, Sign In to add comment