本文主要是介绍蓝桥杯 正则问题 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);
}
}
这篇关于蓝桥杯 正则问题 JAVA的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!