solution.cpp 624 字节
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39
#include <bits/stdc++.h>
#include <cstring>
using namespace std;
string str;
int i = 0;
int dfs()
{
    int mmax = 0, cnt = 0;
    while (i < str.size())
    {
        if (str[i] == '(')
        {
            i++;
            cnt += dfs();
        }
        else if (str[i] == 'x')
        {
            cnt++;
            i++;
        }
        else if (str[i] == '|')
        {
            mmax = max(cnt, mmax);
            i++;
            cnt = 0;
        }
        else
        {
            i++;
            break;
        }
    }
    return mmax = max(mmax, cnt);
}
int main()
{
    cin >> str;
    cout << dfs();
}