反反复复做了37次,人都麻了!!!
  • 板块学术版
  • 楼主_Hu_Tao
  • 当前回复8
  • 已保存回复8
  • 发布时间2022/9/4 22:29
  • 上次更新2023/10/27 12:30:34
查看原帖
反反复复做了37次,人都麻了!!!
750558
_Hu_Tao楼主2022/9/4 22:29

RT,题目链接 求助啊啊啊啊114514,代码如下

#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){
            sb[nn++]=1;
            continue;
        }
        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()){
                    sb[nn++]=0;
                    continue;
                }
                else{
                    if(stk.top()=='('){
                        stk.pop();
                    }else{
                        sb[nn++]=0;
                        continue;
                    }
                }
            }else if(s[j]==']'){
                if(stk.empty()){
                    sb[nn++]=0;
                    continue;
                }else{
                    if(stk.top()=='['){
                        stk.pop();
                    }else{
                        sb[nn++]=1;
                        continue;
                    }
                }
            }
        }
        if(f&&stk.empty())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;
}

建议这洛谷IDE里调,DEV里与实际效果不同

2022/9/4 22:29
加载中...