蓝桥杯 正则问题 JAVA
作者:互联网
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);
}
}
标签:sk,maxX,JAVA,int,蓝桥,正则,num,arrC,tempX 来源: https://blog.csdn.net/Hiraccc_/article/details/122770405