1 条题解

  • 2
    @ 2024-7-25 14:54:32
    #include<bits/stdc++.h>
    using namespace std;
    typedef long long ll;
    string s;
    stack<char>q;
    int main(){
        cin>>s;
        int ans=0;
        for(auto i:s){
            if(q.empty()) q.push(i);
            else if(i==')'&&q.top()=='(') q.pop();
            else q.push(i);
        }
        while(!q.empty()){
            char a=q.top();
            q.pop();
            char b=q.top();
            q.pop();
            if(a==b) ans++;
            else ans+=2;
        }
        cout<<ans;
        return 0;
    }
    
    

    信息

    ID
    2274
    时间
    1000ms
    内存
    125MiB
    难度
    10
    标签
    递交数
    5
    已通过
    5
    上传者