nyoj 2

来源:互联网 发布:伊藤园三得利 知乎 编辑:程序博客网 时间:2024/05/24 05:12
#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;}

0 0