import java.util.*;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
char[] arrC = sc.next().toCharArray();
Stack<Character> sk = new Stack<>();
for (int i = 0; i < arrC.length; i++) {
if (arrC[i] == ')') {
int tempX = 0;
int maxX = 0;
char c = sk.pop();
while (c != '(') {
if (c == '|') {
maxX = Math.max(tempX, maxX);
tempX = 0;
} else if(c == 'x') {
tempX++;
}
c = sk.pop();
}
maxX = Math.max(tempX, maxX);
for (int j = 0; j < maxX; j++) {
sk.add('x');
}
} else {
sk.add(arrC[i]);
}
}
String str = "";
while (!sk.isEmpty()) {
char c = sk.pop();
if (c == 'x' || c == '|')
str += c;
}
String[] s = str.split("\\|");
int num = 0;
for (int i = 0; i < s.length; i++) {
num = Math.max(num, s[i].length());
}
System.out.println(num);
}
}
蓝桥杯 正则问题 JAVA
最新推荐文章于 2024-09-07 19:54:46 发布