1 条题解

  • 3
    @ 2023-10-17 22:55:39

    ///主要用的是栈的知识,左右括号分别进入两个不同的栈,有两个特殊情况要特判

    #include<bits/stdc++.h>
    using namespace std;
    stack <char> sta1;
    stack <char> sta2;
    string s;
    bool bo=true;
    int main()
    {
        cin>>s;
        for(int i=0;i<s.length();i++)
        {
            if(s[i]=='(')
            {
                sta1.push('(');
                bo=false;
            }
            else if(s[i]==')')
            {
                if(bo==true)
                {
                    cout<<"NO";
                    return 0;
                }
                else
                {
                    sta2.push(')');
                    bo=true;
                }
            }
        }
        if(sta1.size()==sta2.size())
        {
            cout<<"YES";
        }
        else
        {
            cout<<"NO";
        }
        return 0;
    }
    
    • 1

    信息

    ID
    2054
    时间
    1000ms
    内存
    128MiB
    难度
    4
    标签
    (无)
    递交数
    165
    已通过
    78
    上传者