求助!!!WA。
  • 板块学术版
  • 楼主_Hu_Tao
  • 当前回复11
  • 已保存回复11
  • 发布时间2022/9/3 16:47
  • 上次更新2023/10/27 12:41:55
查看原帖
求助!!!WA。
750558
_Hu_Tao楼主2022/9/3 16:47

题目链接

#include <bits/stdc++.h>
using namespace std;
int sb[1000005];
int main() {
    int n,nn=0;
    cin>>n;
    getchar();
    string s;
    getline(cin,s);
    for(int i=1;i<=n;i++){
        getline(cin,s);
        stack<char>stk;
        while(!stk.empty())stk.pop();
        int f=1;
        int x=s.size();
        if(x==0){
            f=1;
        }
        for(int j=0;j<x;j++){
            if(s[j]=='('){
                stk.push('(');
            }else if(s[j]=='[')
            {
                stk.push('[');
            }else if(s[j]==')'){
                if(stk.empty()){
                    f=0;
                }
                else{
                    if(stk.top()=='('){
                        stk.pop();
                    }else{
                        f=0;
                    }
                }
            }else if(s[j]==']'){
                if(stk.empty()){
                    f=0;
                }else{
                    if(stk.top()=='['){
                        stk.pop();
                    }else{
                        f=0;
                    }
                }
            }
        }
        if(f)sb[nn++]=1;
        else sb[nn++]=0;
    }
    for(int i=0;i<nn;i++){
        if(sb[i]==1){
            cout<<"Yes"<<endl;
        }else{
            cout<<"No"<<endl;
        }
    }
    return 0;
}

2022/9/3 16:47
加载中...