75分求助!!
查看原帖
75分求助!!
977778
__Harry_Haiyun__楼主2023/8/8 21:20
#include <iostream>
#include <stack>
using namespace std;
int main()
{
    //freopen("kuohao.in","r",stdin);
    //freopen("kuohao.out","w",stdin);
    string s;
    cin >> s;
    stack<char>st;
    for (int i = 0; i < s.size(); i++)
    {
        if (s[i] == '(') st.push(s[i]);
        else
        {
            if(st.size() && st.top() == '(') st.pop();
            else st.push(')');
        }
    }
    int l = 0;
    int r = 0;
    while (st.size())
    {
        if (st.top() == '(') l++;
        else r++;
        st.pop();
    }
    cout << l/2+r/2;
    //fclose(stdin);
    //fclose(stdout);
    return 0;
}
2023/8/8 21:20
加载中...