AcWing 1225. 正则问题
原题链接
中等
作者:
数码宝贝贝
,
2024-03-14 14:07:28
,
所有人可见
,
阅读 10
#include <iostream>
#include <cstring>
#include <algorithm>
using namespace std;
const int N = 110;
string str;
int k;
int dfs()
{
int res=0;
while(k<str.size())
{
if(str[k]=='(')
{
k++;//跳过'('
res+=dfs();//表示括号里有多少x就加上多少x
k++//跳过')'//因为下面等有右括号的时候是直接break了,并没有跳过
//为什么不能在下面跳过右括号捏
}
else if(str[k]=='|')
{
k++;//跳过
res=max(res,dfs());//左右取最大值
}
else if(str[k]==')'){break;}
else
{
res++;
k++;
}
}
return res;
}
int main()
{
cin>>str;
cout<<dfs()<<endl;
return 0;
}