WA求助!!!!!!!!!
  • 板块学术版
  • 楼主_Hu_Tao
  • 当前回复1
  • 已保存回复1
  • 发布时间2022/8/19 12:21
  • 上次更新2023/10/27 14:37:45
查看原帖
WA求助!!!!!!!!!
750558
_Hu_Tao楼主2022/8/19 12:21

题目链接

#include <bits/stdc++.h>
using namespace std;
int main() {
    string s;
    int n;
    cin>>n;
    for(int i=1;i<=n;i++){
        cin>>s;
        stack<char>stk;
        int f=1;
        int x=s.size();
        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==1&&stk.empty()){
            cout<<"Yes\n";
        }else cout<<"No\n";
    }
    return 0;
}

2022/8/19 12:21
加载中...