P1321 - [蓝桥杯2017初赛]正则问题 - New Online Judgehttp://oj.ecustacm.cn/problem.php?id=1321
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int Index = 0;
string str;
int kuoHao() { // 一对括号里至少有一个 |
int res = 0;
int temp = 0;
for(Index+=1; Index < str.length(); Index++) {
if (str[Index] == ')') {
return max(res, temp);
} else if (str[Index] == 'x') {
temp++;
} else if (str[Index] == '(') {
temp += kuoHao();
} else if (str[Index] == '|') {
res = max(res, temp);
temp = 0;
}
}
return res;
}
int main() {
getline(cin, str);
int temp = 0;
int res = 0;
for(Index=0; Index<str.length(); Index++) {
if (str[Index] == 'x') {
temp++;
} else if (str[Index] == '(') {
temp += kuoHao();
} else if (str[Index] == '|') {
res = max(res, temp);
temp = 0;
}
}
cout << max(res, temp);
return 0;
}