蓝桥杯 正则问题 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);
    }
}

上一篇:3.状态机与ABCI


下一篇:linux源码解读(二十一):网络通信简介——tcp三次握手