nyoj 2

#include <iostream>
#include <stack>
#include <string.h>
#include <stdio.h>
using namespace std;
char a[10001];
int main()
{
    int i,t,flag,n;
    cin>>t;
    getchar();
    stack<char> s;
    while(t--)
    {
        cin.getline(a,10001);
        n=strlen(a);
        s.push(a[0]);
        flag=1;
        for(i=1;i<n;i++)
        {
            //if((a[i]==')'||a[i]==']')&&s.empty())
            //{flag=0;break;}
        if(s.top()=='('&&a[i]==')')
             {/*cout<<s.top()<<endl; */s.pop();}
        else if(s.top()=='['&&a[i]==']')
             {/*cout<<s.top()<<endl; */s.pop();}
        else s.push(a[i]);
        }
        //cout<<endl;

        //cout<<s.top()<<endl;
       // s.pop();
       // cout<<s.empty()<<endl;

            if(s.empty()&&flag)   cout<<"Yes\n";
            else
                cout<<"No\n";
                while(!s.empty())
			s.pop();
    }
    return 0;
}

posted @ 2014-12-11 17:37  __夜风  阅读(106)  评论(0编辑  收藏  举报