求助
查看原帖
求助
207812
Chouquet楼主2020/8/3 14:07

提交好久都不过QAQ

#include <cstdio>
#include <cstring>
#include <stack>
bool work(){
    char a[131];std::stack<char> s;
    scanf("%s",a);
    if(!strlen(a)) return 1;
    for(int i=0;a[i];i++){
        if(a[i]=='('||a[i]=='[') s.push(a[i]);
        else{
            if(s.empty()||(a[i]==')'&&s.top()=='[')||(a[i]==']'&&s.top()=='('))
                return 0;
            s.pop();
        }
    }
    return s.empty();
}
int main(){
    int n;scanf("%d",&n);
    while(n--) puts(work()?"Yes":"No");
    return 0;
}
2020/8/3 14:07
加载中...