“ans”

wurenchao 2022-12-18 16:15:40 6 返回题目

不许复制!!!

#include<bits/stdc++.h>

using namespace std;

int k[10001],l=0;

void push(int x){k[l]=x;++l;}

void pop(void){--l;}

int size(void){return l;}

int top(void){return k[l-1];}

int main(){

int n;

string s;

cin>>n;

for(int i2=1;i2<=n;i2++){

    cin>>s; 

    for(int i=0;i<s.size();i++){

        if(s[i]=='<') push(1);

        if(s[i]=='(') push(2);

        if(s[i]=='[') push(3);

        if(s[i]=='{') push(4);

        if(s[i]=='>'){

            if(top()==1) pop();

            else push(5);

        }

        if(s[i]==')'){

            if(top()==2) pop();

            else push(6);

        }

        if(s[i]==']'){

            if(top()==3) pop();

            else push(7);

        }

        if(s[i]=='}'){

            if(top()==4) pop();

            else push(8);

        }

    }

    if(size()==0) cout<<"YES\n";

    else cout<<"NO\n";

    l=0;

}

return 0;

}

{{ vote && vote.total.up }}