”|”:表示二者取其一
“&”:表示直接相连
#include <iostream>
#include <cstring>
#include <algorithm>
using namespace std;
int k;
string str;
int dfs()
{
int res = 0;
while (k < str.size())
{
if (str[k] == '(') //处理 (......)
{
k ++ ; //跳过'('
res += dfs();
k ++ ; //跳过')'
}
else if (str[k] == '|')
{
k ++ ; //跳过'|'
res = max(res, dfs());
}
else if (str[k] == ')') break;
else //再否则就是x,长度直接++
{
res ++ ;
k ++ ; //跳过x
}
}
return res;
}
int main()
{
cin >> str;
cout << dfs() << endl;
return 0;
}